0
我有一個骨幹應用程序視圖,向用戶解釋他們沒有任何數據要顯示,並單擊按鈕創建一些數據。在主幹中更改視圖:最大調用堆棧優於
創建一些數據會向我的服務器發送一個POST請求,然後又將一個模型添加到一個集合中,集合上有一個監聽器。
this.listenTo(this.collection, "add", this.addOneClient);
從上面可以看到,這則觸發一個方法,
addOneClient: function(model) {
if(this.collection.length == 1) {
this.$el.empty();
this.render();
}
var clientEntry = new Pops.Views.ClientListEntry({
model : model,
user : this.options.user
});
this.$('.client-list-table').append(clientEntry.render().el);
},
所以基本上是一個視圖添加到父視圖,但檢查該模型是一個集合作爲唯一一個如果是,我們需要刪除任何數據視圖,並創建父視圖,父視圖在渲染方法創建,
render: function() {
if(this.model.get('clients').length > 0) {
this.$el.html(this.template({ //Originally Maximum callstack was being exceeded here
organisation : this.model.toJSON(),
user: this.options.user.toJSON()
}));
} else {
var noView = new Pops.Views.NoView({
text : "There are currently no clients, <a href='#' data-create='client'>click here</a> to create one."
});
return this.$el.html(noView.render().el);
}
var filter = Pops.Session.get('organisation_filters').findWhere({ organisation_id : this.model.get('id') });
var sorting = filter.get('list_sorting').split(",");
this.collection.sortByField(sorting[0], sorting[1]);
this.$('.js-sort-client-projects').removeClass('active');
if(sorting[1] == "desc") {
this.$('.js-sort-client-projects[data-sort="' + sorting[0] + '"]').attr('data-order', 'asc');
this.$('.js-sort-client-projects[data-sort="' + sorting[0] + '"]').removeClass('desc').addClass('asc active');
} else {
this.$('.js-sort-client-projects[data-sort="' + sorting[0] + '"]').attr('data-order', 'desc');
this.$('.js-sort-client-projects[data-sort="' + sorting[0] + '"]').removeClass('asc').addClass('desc active');
}
this.addAll(); //Added this.$el.empty to addOne method, maximum callstack being exceeded here now.
},
本來Maximimum調用堆棧是在渲染方法的突破,WH恩我推模板到this.$el
,然後我在我的addOneMethod清空這一點。$ EL,當我打電話則addAll方法超出了調用堆棧,
addAll: function() {
this.$('.client-list-table').find('tbody').empty();
this.collection.each(this.addOneClient, this);
},
我不知道什麼是錯我的代碼,任何人都可以擺脫任何光?
它確實提供了一個答案。 – Udders