現在、値をフェッチするコレクションがあり、その後、リセット イベントに関連付けられたすべてのビューが再度レンダリングされます。
問題は、取得したレコードの総数を取得するために別のクエリも発行する必要があり、その ajax 呼び出しが完了した後でのみ、リセット イベントがトリガーされる必要があることです。
少しのコードでより明確になります:
fetch: function() {
options = { data: this.getParams() };
this.fetch_total();
return Backbone.Collection.prototype.fetch.call(this, options);
},
fetch_total: function() {
var that = this;
var options = {
url: this.url + '/count',
data: this.getParams(),
contentType: 'application/json',
success: function(resp, status, xhr) {
that.total = parseInt(resp);
return true;
}
};
return $.ajax(options);
}
ご覧のとおり、エンティティの数を取得するには、get to localhost/myentity/count を発行する必要があります...
問題は、ビューを更新する前に collection.total 変数を更新する必要があることです。つまり、すべてのビューを更新する前に、localhost/myentity への GET と localhost/myentity/count への GET の両方の要求を完了する必要があります...
どうすればそれを達成できますか?