qualityStore = new Ext.data.Store({
url: '../action/submitOrderController.zcjs?funcflg=getQuality&breedId='+breedId,
reader: new Ext.data.XmlReader({
record: 'Item',
id: 'ItemId'
}, [
'id','name'
])
});
qualityStore.on('load',AJAX_Loaded_qualityStore, this, true);
qualityStore.load();
alert("qualityStore.getCount(): "+qualityStore.getCount());
..................
...............
当store中的数据还没有取出来时,后面的代码已经执行了,所要每次alert的数据都是0,后面执行的操作也获取不了数据,怎么办?
ext-basex.js导入在ext-all.js后面。
实在不行你通过store回调函数写吧。
qualityStore.on('load',function(){
alert(qualityStore.getCount());
}, this, true);
通过 store 回调函数同步。或者让store使用同步数据加载。如果是3.0以下需要加ajax同步代码。
new Ext.data.JsonStore({
proxy:Ext.data.HttpProxy({
sync : true
})
})
/*******************************************************************************
设置Ext Ajax同步
******************************************************************************/
Ext.lib.Ajax.request = function(method, uri, cb, data, options) {
if (options) {
var hs = options.headers;
if (hs) {
for (var h in hs) {
if (hs.hasOwnProperty(h)) {
this.initHeader(h, hs[h], false);
}
}
}
if (options.xmlData) {
if (!hs || !hs['Content-Type']) {
this.initHeader('Content-Type', 'text/xml', false);
}
method = (method ? method : (options.method
? options.method
: 'POST'));
data = options.xmlData;
} else if (options.jsonData) {
if (!hs || !hs['Content-Type']) {
this.initHeader('Content-Type', 'application/json', false);
}
method = (method ? method : (options.method
? options.method
: 'POST'));
data = typeof options.jsonData == 'object' ? Ext
.encode(options.jsonData) : options.jsonData;
}
}
return this"sync" in options ? "syncRequest" : "asyncRequest";
}
Ext.lib.Ajax.syncRequest = function(method, uri, callback, postData) {
var o = this.getConnectionObject();
if (!o) {
return null;
} else {
o.conn.open(method, uri, false);
if (this.useDefaultXhrHeader) {
if (!this.defaultHeaders['X-Requested-With']) {
this
.initHeader('X-Requested-With', this.defaultXhrHeader,
true);
}
}
if (postData && this.useDefaultHeader
&& (!this.hasHeaders || !this.headers['Content-Type'])) {
this.initHeader('Content-Type', this.defaultPostHeader);
}
if (this.hasDefaultHeaders || this.hasHeaders) {
this.setHeader(o);
}
o.conn.send(postData || null);
this.handleTransactionResponse(o, callback);
return o;
}
}
首先我上面代码加上用来设置ajax同步
qualityStore = new Ext.data.Store({
proxy:Ext.data.HttpProxy({
sync : true,//设置同步
url: '../action/submitOrderController.zcjs?funcflg=getQuality&breedId='+breedId
}),
reader: new Ext.data.XmlReader({
record: 'Item',
id: 'ItemId'
}, [
'id','name'
])
});
qualityStore.on('load',AJAX_Loaded_qualityStore, this, true);
qualityStore.load();
alert("qualityStore.getCount(): "+qualityStore.getCount());
你使用的是什么版本的
是Ext.lib.Ajax.request出现错误吗?
3.0使用下载ext-basex.js实现同步
qualityStore = new Ext.data.Store({
proxy:Ext.data.HttpProxy({
async: false,//设置同步
url: '../action/submitOrderController.zcjs?funcflg=getQuality&breedId='+breedId
}),
reader: new Ext.data.XmlReader({
record: 'Item',
id: 'ItemId'
}, [
'id','name'
])
});