Angular JS从单独的数组中过滤出使用过的id

时间:2014-09-19 20:38:01

标签: arrays angularjs angularjs-ng-repeat

我有一个文章的对象,其中包含ng-repeat中id的网站上的所有文章。我还在id中重复附加文章的产品对象中有一个数组。

尝试仅显示尚未附加到产品的文章。不确定如何遍历数组并查找匹配项并将其从返回的对象中排除。

https://gist.github.com/irthos/0565c66be0ab992adc0a

有没有办法可以ng-repeat =“文章中的文章|(除了任何product.articles。$ id === article。$ id)”?

1 个答案:

答案 0 :(得分:1)



var app = angular.module('app', []);
app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.search = 1;

  $scope.familes = [{
    id:1,
    name: "Kruders",
    kids: [
      { name: "zoe" } 
      ]
},

{
  id:2,
    name: "Halifax",
    kids: [
      { name: "mike" } ,
      { name: "jim" } 
      ]
},

{
  id:3,
    name: "Judes",
    kids: [
     
      ]
}]
});

<html ng-app="app">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-controller="MainCtrl">
  <input type="number" ng-model="search" />



  <ul>
    <li ng-repeat="family in familes | filter  :{id:'!'+search}">id: {{family.id}} - Name:{{family.name}}</li>
  </ul>

</body>
  </html>
&#13;
&#13;
&#13; 请参阅该演示,它应该有助于http://plnkr.co/edit/MNqBhOd1Y5GVezfa8zj0?p=preview

ng-repeat="article in articles | filter :{id:'!'+product.articles.$id})