Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ExtJS4中将成功处理程序附加到Treestore的ajax代理?_Ajax_Extjs_Extjs4 - Fatal编程技术网

如何在ExtJS4中将成功处理程序附加到Treestore的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' },

下面是我对加载存储的服务器的ajax调用:

   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               
        }
    }
});