Brian Wendt
Brian Wendt

Reputation: 83

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.

Upvotes: 3

Views: 1428

Answers (2)

yellowcakeuranium
yellowcakeuranium

Reputation: 21

I know this is old, but for people like me that were searching for the same question... If you want to save the entire structure instead of just the modified lines, you need to define a writer in your store proxy and in that writer, set writeAllFields: false:

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);
        }
    },
    writer: {
        type: 'json',
        writeAllFields: true
    }
},

Upvotes: 2

dbrin
dbrin

Reputation: 15673

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.

Upvotes: 2

Related Questions