我創建了一個嵌套的樹,可能有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
您應該使用虛擬/無限滾動 - 無論是現有滾動還是開發您自己的滾動。沒有別的會真的幫助。 –