如何在ExtJS4中将成功处理程序附加到Treestore的ajax代理?
下面是我对加载存储的服务器的ajax调用:如何在ExtJS4中将成功处理程序附加到Treestore的ajax代理?,ajax,extjs,extjs4,Ajax,Extjs,Extjs4,下面是我对加载存储的服务器的ajax调用: function setUpStore(Id){ store = Ext.create('Ext.data.TreeStore', { storeId:'jsonStore', proxy: { type: 'ajax', url: 'fetchData.action?ID='+Id, reader: { type: 'json' },
function setUpStore(Id){
store = Ext.create('Ext.data.TreeStore', {
storeId:'jsonStore',
proxy: {
type: 'ajax',
url: 'fetchData.action?ID='+Id,
reader: {
type: 'json'
},
success : function(resp){
alert("success!!!");
}
}
});
}
调用下面的java方法,该方法返回一个JSON对象:
公共字符串fetchJSONObj(){
从服务器获得响应后,我没有收到成功处理程序中提到的警报。我是否正确声明了它
谢谢,代理服务器没有名为success的配置选项 根据您的代码,您可以挂接商店的加载事件:
function setUpStore(Id){
store = Ext.create('Ext.data.TreeStore', {
storeId:'jsonStore',
proxy: {
type: 'ajax',
url: 'fetchData.action?ID='+Id,
reader: {
type: 'json'
},
},
listeners: {
load: {
fn: function() {
// Do something here.
},
},
scope: this
}
}
});
如果手动加载,还可以将回调作为参数传递给加载函数
function setUpStore(Id){
store = Ext.create('Ext.data.TreeStore', {
storeId:'jsonStore',
proxy: {
type: 'ajax',
url: 'fetchData.action?ID='+Id,
reader: {
type: 'json'
},
},
listeners: {
load: {
fn: function() {
// Do something here.
},
},
scope: this
}
}
});