本文實(shí)例講述了Angularjs的ng-repeat中去除重復(fù)數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:
一、JS:
ngApp.filter('unique', function () { return function (collection, keyname) { var output = [], keys = []; angular.forEach(collection, function (item) { var key = item[keyname]; if (keys.indexOf(key) === -1) { keys.push(key); output.push(item); } }); return output; };});二、Html:
<div ng-repeat="item in items | unique: 'id'"></div>
希望本文所述對大家AngularJS程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答