私は、表示するデータがないことをユーザーに説明し、ボタンをクリックしてデータを作成するビューをバックボーンアプリケーションに持っています。バックボーンのビューを変更する:最大呼び出しスタックExcedeed
いくつかのデータを作成すると、サーバーにPOSTリクエストが送信され、モデルaがコレクションに追加されます。コレクションにはリスナーがあります。あなたは、これは、メソッドを発射していることがわかります以上のことから
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メソッドで作成され、
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コールスタックはrenderメソッド、WHに超えていました私はthis.$el
にテンプレートをプッシュし、私はこれを空にします。私のaddOneMethodで$エル、と私はのaddAllメソッドを呼び出すときにコールスタックは、
addAll: function() {
this.$('.client-list-table').find('tbody').empty();
this.collection.each(this.addOneClient, this);
},
を超えている途中、私は、私のコードで何が間違っている見当がつかない誰でも光を当てることができますか?
それは答えを提供したと思います。 – Udders