我有两个我关心的模型/代理/商店Questions
和Choices
. 两者都以 JSON 格式从 REST 服务器获取数据。我的流程目前是这样的:
// load numQuestions records from store.Questions
var qs = Ext.getStore('Question');
//... loadmask, etc.
qs.load({
scope : this,
params : {
limit : numQuestions
},
callback : function() {
this.createQuestionCards(numQuestions);
}
});
一旦我有了Questions
,我就会遍历并获取与Choices
每个相关的内容,Question
例如:
for ( i = 0; i < numQuestions; i++) {
// ... misc ...
Assessor.questionChoices[i] = qs.getAt(i).choices();
// ...misc...
},
这很好用,除了它为每个循环迭代生成一个 XMLHTTPRequest。最小响应时间在 0.15 秒区域内,这对于 N < ~40 来说很好。一旦数字达到 200(这应该是一个常见的用例),延迟就会很糟糕。
如何让 ExtJS “批处理”请求并在循环体之后发送它们?例如:
var choiceBatch = qs.createBatch();
for ( i = 0; i < numQuestions; i++) {
// ... misc ...
Assessor.questionChoices[i] = choiceBatch.getAt(i).choices();
// ...misc...
};
choiceBatch.execute();