我创建了一个嵌套的树,可能有1 - 5000项,我能够使它发挥作用,但它只是显示之前冻结我的浏览器\正在加载的旋转几秒钟树。如何处理,因为浏览器冻结嵌套NG-重复
我怎样才能使它平滑,因此浏览器将永远定格?
我怎么能知道什么时候angularjs完成创建或渲染或计算(不知道正确的字),整个列表,这样我可以删除加载微调的话,你可以看到的范围。最后$将无法正常工作我们已经嵌套NG重复和同为范围$父$最后
这里是plunker我创建,但与演示数据 - 。
http://plnkr.co/edit/GSZEpHjt5YVxqpg386k5?p=preview
实例Da taset - http://pastebin.com/YggqE2MK
在这个例子中这不是太糟糕,但是在我的浏览器冻结了10秒以上,我的OWN设置中有大约4000个项目与所有其他组件。
我已经考虑
- 使用bindonce.js库,但不使用“::”单一的结合不是很成功很成功
- 再次
- 只加载第一级然后渲染一个新的水平当用户展开一个类别,但我的树可以很随意,也许我只是有数百个子节点1个单根节点
- 分页是不理想的情况下
HTML
<script type="text/ng-template" id="tree_item">
<div ng-init="category.expanded=true">
<div ng-class="{'selected': category.ID==selectedCategoryID}">
<div class="icon icon16" ng-if="category.Children.length>0" ng-click="$parent.category.expanded=!$parent.category.expanded" ng-class="$parent.category.expanded?'col':'exp'"></div>
<div class="icon icon-category" ng-class="'icon-category-'+category.TypeType" ng-style="{'border-color':category.Colour}" ng-attr-title="{{category.Status?Res['wpOPT_Status'+category.Status]:''}}"></div>
<a ng-href="#id={{category.ID}}" ng-class="{'pending-text': category.PendingChange}">{{category.Name}}</a>
</div>
<ul class="emlist" ng-show="category.expanded">
<li ng-repeat="category in category.Children | orderBy:'Name'" ng-include="'tree_item'" ng-class="{'selected': category.ID==selectedCategoryID}" e2-tree-item is-selected="category.ID==selectedCategoryID">
</li>
</ul>
</div>
</script>
<div id="CategoryListContainer" class="dragmenu-container initial-el-height">
<div class="spinner" data-ng-show="status=='loading'"></div>
<ul id="CategoryList" class="dragmenu-list ng-cloak" ng-show="status=='loaded'">
<li ng-repeat="category in tree | orderBy:'Name'" ng-include="'tree_item'" e2-tree-item is-selected="category.ID==selectedCategoryID"></li>
</ul>
</div>
JS
var app = angular.module('recursionDemo', []);
app.controller("TreeController", function($scope, $timeout) {
$scope.status = "loading";
$timeout(function() {
var result = {
"GetCategoryTreeResult": [{ // too big data set so I pasted it here http://pastebin.com/YggqE2MK }];
$scope.tree = result.GetCategoryTreeResult;
$scope.status = "loaded";
}, 3000);
});
app.directive('e2TreeItem', function($timeout) {
function link(scope, element, ngModel) {
scope.$watch('isSelected', function(oldVal, newVal) {
if (scope.isSelected === true) {
element.parentsUntil('#CategoryListContainer', 'li').each(function(index, item) {
angular.element(item).scope().category.expanded = true;
});
}
});
// not working
//if (scope.$parent.$last) {
// console.log("last has been caught");
// var appElement = document.querySelector('[ng-app=recursionDemo]');
// angular.element(appElement).scope().status = "loaded";
//}
}
return {
link: link,
scope: {
isSelected: '=?'
}
};
});
建议:您可以使用单向绑定进行ng-repeat或延迟加载ng-repeat,这可能会对您有所帮助。 –
使用'track by'可以极大地提高性能 – Ladmerc
您应该使用虚拟/无限滚动 - 无论是现有滚动还是开发您自己的滚动。没有别的会真的帮助。 –