首页 > Angular 中用ng-repeat搞的列表项,我想点击其中一个列表项就将改项隐藏改怎么做

Angular 中用ng-repeat搞的列表项,我想点击其中一个列表项就将改项隐藏改怎么做

<tr ng-repeat = "app in apps" ng-hide = "">
            <td>
                <a  data-uk-modal="{target:'#{{app._id}}'}">{{app.name}}</a>
            </td>
            <td>{{app._id}}</td>
            <td>{{app.author}}</td>
            <td>{{appCategoryMap[app.category].name}}</td>
            <td>
                <a  class="uk-button uk-button-danger" ng-click  = "underCarriage(app._id)">下架</a>
            </td>

        </tr>

ng-hide里面应该怎么去写,如果写入变量的话,全部的列表项都是同一个ng-hide变量无法隐藏单个


给apps加个hidden属性记录是否隐藏

http://jsfiddle.net/larvata/1wr2bfLs/


请认真描述你的问题嘛,这样别人才会认真对你的问题嘛。

你就是想要点击“下架”然后这一行就从表格里面消失。其实就是删除数据里面一个记录,AngularJS的绑定机制会自动的更新界面,这一行也就会自动消失了。不需要使用ng-hide

你只需要好好实现underCarriage(app._id)即可:

controllers.controller('SFTestCtrl', ['$scope', function($scope) {
  $scope.apps = [
    {
      _id: 0,
      name: 'test',
      author: 'test',
      category: 'test'
    },
    {
      _id: 1,
      name: 'test1',
      author: 'test1',
      category: 'test1'
    },
    {
      _id: 2,
      name: 'test2',
      author: 'test2',
      category: 'test2'
    }
  ];

  $scope.appCategoryMap = {
    test: {
      name: 'test'
    },
    test1: {
      name: 'test1'
    },
    test2: {
      name: 'test2'
    }
  };

  $scope.underCarriage = function(id) {
    $scope.apps.forEach(function(v, i, _) {
      if (v._id == id) {
        _.splice(i, 1);
      }
    });
  };

}]);

我本地测试可以达到效果。

【热门文章】
【热门文章】