带有Custom ng repeat指令的Custom Filter和LimitTo选项
Custom Filter and LimitTo options with Custom ng-repeat directive
我有以下代码,其中我有一个nested ng-repeat
,并且在内部ng重复中使用filter
和limitTo
选项
http://jsfiddle.net/WqSGR/27/
在这里,我的套装里的东西很少。但在我的真实案例中,我有大约1000个外循环和内循环项目。但我面临着使用ng重复进行大量设置的问题——Angular JS ng重复会消耗更多的浏览器内存
所以我有了自己的ng重复,这大大减少了内存使用:
http://jsfiddle.net/WqSGR/28/
但是,我可以在我的自定义ng repeat指令中使用类似于上面的ng repeat的filter
和limitTo
选项吗?
注意:内部ng重复不会总是限制为5。我有一个用于内ng重复的内卷轴,上面有一个watch
,当内卷轴到达终点时,将限制增加5。
非常感谢您的帮助!
我尝试过的最接近的是:http://jsfiddle.net/WqSGR/29/
但是,有人能帮助如何在searchText
上应用手表以使过滤器工作吗?
是的,您可以在链接函数中使用过滤器:
myApp.directive('myRepeater', function(filterFilter, limitToFilter) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var myTemplate = "<div>{{rating}}</div>";
var filteredItems = filterFilter(scope.items, scope.SearchText);
var limitedItems = limitToFilter(filteredItems, 5);
angular.forEach(limitedItems, function(item){
var text = myTemplate.replace("{{rating}}",item.rating);
element.append(text);
});
}
};
});
然后,您将继续创建$watches来观察scope.SearchText
和scope.NumberOfItems
上的更改,从而相应地更新列表。
相关文章:
- Javascript Custom Base32
- 性能与模块化:将JS集成到PHP或单独的custom.JS中
- orderBy和limitTo在ng个重复子项中
- Angular limitTo未返回正确的输出
- JavaScript 的全新功能,使用 Google Maps API v3 w/ custom fitbounds (
- Appcelerator Android Custom Fonts不起作用
- 为什么javascript函数名称custom是一个小写的单词,后跟一个大写的单词,就像'orangeCost'一样
- Custom HTML - Rally TreeGrid
- AngularJS ngRepeat不尊重limitTo筛选器
- limitTo not working in ng-repeat in AngularJs
- 升级至Knockout 3.0.0,Templates/Custom Binding Handlers不再工作
- Javascript Windows Azure Mobile Service Client With Custom A
- JavaScript RegExp Custom URL validation with ${protocol}
- Custom clipping path over HTML <div>
- querySelectorAll with custom library
- 使用 ng-repeat 和 limitTo 来限制显示的可见项目数
- 使用 data-custom=“” 绑定到事件
- Jquery Custom ScrollBar ( Malihu - mCustomScrollBar ) 不起作用
- angularjs ng-repeat: limitTo not limiting object loop
- 带有Custom ng repeat指令的Custom Filter和LimitTo选项