标签:extjs javascript 闭包
for (var i = 0; i < 10; i++) { var dateRange = {}; dateRange.start = start + i*deta; dateRange.end = start + (i+1)*deta - 1; Ext.Ajax.request({ url: ajax_url, params: { start: dateRange.start, end: dateRange.end, }, success: function (response, options) { ... // 注意此处用到闭包, i 已经变成最大值了 conosle.log(i); } }); }
function requestData(i) { var dateRange = {}; dateRange.start = start + i*deta; dateRange.end = start + (i+1)*deta - 1; Ext.Ajax.request({ url: ajax_url, params: { start: dateRange.start, end: dateRange.end, }, success: function (response, options) { ... conosle.log(i); } }); } for (var i = 0; i < 10; i++) { requestData(i); }
Ext.Ajax.request({ url: ajax_url, // 设定为同步请求方式 async: false, params: { start: dateRange.start, end: dateRange.end, }, success: function (response, options) { ...
标签:extjs javascript 闭包
原文地址:http://blog.csdn.net/lvye1221/article/details/39525967