在Angular.JS-ng隐藏vs过滤器中将对象分隔为两组

Separate objects to two groups in Angular.JS - ng-hide vs filter

本文关键字:分隔 两组 对象 JS-ng Angular 隐藏 vs 过滤器      更新时间:2023-09-26

我有一个对象,其中包含我想要分离并显示在两个列表中的数据。对象看起来例如:

var data = [
   {name: "Something 1", active: 1, datetime: "goes", author: "here"},
   {name: "Something 2", active: 0, datetime: "goes", author: "here"},
   {name: "Something 3", active: 0, datetime: "goes", author: "here"}
];

正如您可能猜测的那样,我想要单独的活动和非活动数据。这样做有什么更好的呢?

过滤器:

<li ng-repeat="out in data | filter:{'active':1}">{{out.name}}</li>

或者ng隐藏(用于非活动):

<li ng-repeat="out in data" ng-hide="out.active">{{out.name}}</li>

您真的需要非活动元素在DOM树上吗?

如果没有,请使用ng-If,这样就不会将不必要的HTML加载到文档中。