Search code examples
ajaxjsontreeextjs4

extjs TreeStore proxy with dynamic update api


From my extended Ext.data.TreeStore:

proxy: {
    type: 'ajax',
    api: {
        read: "/GetTree.json",
        update: "/SetTree.aspx?username=user1"
    },
    reader: {
        type: 'json',
        root: 'children'
    },
    listeners: {
        exception: function (proxy, response, options) {
            // error case
            console.log('Exception in Portlets store proxy...');
            console.log(response);
        }
    }
},

What I am trying to figure out is how can I make the username=user1 dynamic, such that I could pass in user2 and have the aspx page process with that user data.

I cannot figure out if/how TreeStore.sync() allows parameters to be passed into it.

Update:

What I am really after here is the ability to save back the entire tree structure as a JSON string instead of just the record that was updated. I can build the JSON string I need to pass but cannot figure out how to actually get that information to my SetTree.aspx page.


Solution

  • You can try setting extra params on the proxy before calling sync:

    store.proxy.extraParams = { param1 : '', param2 : '' };
    

    There is anecdotal evidence that suggests this works in 4.1.3 but not earlier versions.

    Another thought is to just fire a regular Ajax.request and send desired params along instead of using the tree store to do that.