我想使用ajax请求成功的var ajaxRe
值,
在ajax请求之外,但值为undefined
。我想使用响应来加载网格中的数据,
Ext.Ajax.request({
url : myUrl,
params : {
myParamList
},
success : function(re,action) {
var ajaxRe = re.responseText;
...
var respArr = ..;
},
failure : function(form,action) {
console.log("fail");
}
});
当我在成功中打印grid.getStore()
时,网格包含我需要的数据,但它没有显示,
我正在网格商店中成功设置数据,并在外面访问网格。
success : function(re,action) {
that.editorGrid.getStore().data = respArr;
}
我该如何解决这个问题?
由于
答案 0 :(得分:2)
如果数据格式正确,请尝试以下
that.editorGrid.getStore().loadData(respArr);
如果要使用代理阅读器加载数据,请使用
that.editorGrid.getStore().loadRawData(respArr);
另一种方法是重新配置存储并将该存储绑定到网格
var store = Ext.create('Model', {
autoLoad: true,
data: responseJson,
proxy: {
type: 'memory',
reader: {
type: 'json'
}
}
});
that.editorGrid.bindStore(store);
答案 1 :(得分:1)
我同意Saki你应该使用商店来填充网格,所以如果它没有重新加载,可能还有另外一个问题。
无论如何,要回答你的问题:只需在ajax请求之外定义ajaxRe:
var ajaxRe = '';
Ext.Ajax.request({
...
ajaxRe = re.responseText;
...
});
但请注意,在实际设置值之前,您可能会尝试访问变量。
答案 2 :(得分:0)
您不需要单独的请求来填充(网格)商店。在商店中定义代理,Ext负责其余部分。您还可以查看this example,查看代码并分析传输到服务器并返回的数据。