![](/img/trans.png)
[英]How to calculate sum on a row in AngularJS without triggering digest cycle?
[英]How to add item into array and make it appear at the top, without triggering multiple digest cycles?
http://plnkr.co/edit/HgjGS9LSZ0VhyBMkwy6L?p=preview
vs.unshift = function() {
vs.feedList.unshift(unshifted_item);
};
vs.push = function() {
vs.feedList.push(push_item);
};
在具有API的真實應用中,當我使用unshift
將新警報(通過websocket)添加到警報供稿中時,由於摘要周期的原因,該項目要花很長時間才能添加到數組頂部。 在它每次最終將項目添加到數組頂部之前,似乎每次都在數組中迭代數組中項目的數量(即:10x10)。
但是,如果我們使用push
,則會立即添加新警報,因為Angular不必先檢查數組中的所有其他項。
在上面創建的plnkr示例中很難復制此問題,因為取消移位會立即將該項添加到數組的頂部。 但是,如何使用push
然后將被推入的項目移到數組頂部而不引起摘要循環?
正如@Redu所建議的那樣,拼接方法可以在不導致Angular摘要循環掛起的情況下工作。
feedList.splice(0, 0, item)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.