我有一个列表.每个列表项都包含按钮.当点击一个按钮时,在Ion的另一个视图中查看相应的列表项

i have a list .each list item contains buttons.when click to a button corresponding list item viewed in another view in ionic

本文关键字:列表 按钮 另一个 Ion 视图 包含 有一个 一个      更新时间:2023-09-26

html页面在这里,我在每个列表中有两个按钮。当点击其中一个按钮时,会将该列表项显示在另一页中。当点击下一个项目时,它也会将该项带到同一页。请给我建议或代码。

<ion-view ng-controller="searchctrl as nm">
    <ion-content class="has-header">
        <h2>Courses</h2>
       <label class="item item-input">
           <i class="icon ion-search placeholder-icon">
           </i>
           <input type="search" placeholder="search" ng-model="searchQuery"/>
       </label>
 <ion-list>
    <ion-item class="item-icon-right" ng-repeat="news in newss | filter:searchQuery"
    ng-click= "nm.selectNews(news.name)">
    {{news.name}}
    <div class="buttons">
    <button class="button button-small button-positive" >
   View
</button>

    <button class="button button-small button-positive">
   Add to Mycourse
</button>
    </div>
    </ion-item>
        </ion-list>

js页面

(function(){
var aapp = angular.module('starter');
aapp.controller('searchctrl', function($state, $scope){
$scope.newss = [
    {name: 'HTML'},
      {name: 'JavaScript'},
        {name: 'Angular'},
          {name: 'Ionic'},
           {name: 'Asp.net'}
]
var nm=this;
nm.selectNews = function(newsname){
  console.log(newsname);
  $state.go(newsname);
}
});
}());

首先使用一个数组来存储如下所选的项目:

$scope.cart = [];

然后,添加此功能,它将首先检查该项目是否已添加,然后增加数量,否则项目将被推到购物车阵列中。

$scope.addToCart = function (product) {
            var found = false;
            $scope.cart.forEach(function (item) {
                if (item.id === product.id) {
                    item.quantity++;
                    found = true;
                }
            });
            if (!found) {
                $scope.cart.push(angular.extend({quantity: 1}, product));
            }
        };

希望这对你有帮助。。有什么疑问吗?