如何在EXTJS 4中将成功处理程序附加到Treestore的ajax代理?

时间:2012-06-26 06:37:03

标签: 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'
        },
        success : function(resp){
            alert("success!!!");
        }
    }
});

}

调用以下返回JSON对象的java方法:

public String fetchJSONObj(){

              HttpServletResponse res = ServletActionContext.getResponse();
              HttpServletRequest req  = ServletActionContext.getRequest();

    ID = (String) req.getParameter("ID");
    res.setHeader("Content-Type", "application/json");

    VendorVO root= ServiceHelper.getInstance().getService().getData(ID);


    Data = new ExtJsTreeWrapper();
    Data.setText(ID);
    Data.setId(ID);
    Data.getChildren().add(convertVOToExtJSWrapper(root));
    return SUCCESS;
}

从服务器获得响应后,我没有收到成功处理程序中提到的警报。我能正确宣布吗?

由于

1 个答案:

答案 0 :(得分:2)

代理没有获得名为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               
        }
    }
});

如果您手动加载,您还可以将回调作为参数传递给加载函数。