is there a way to attach jsondata to a POST request for loading a store? I know it's possible through a GET request by simply adding params : {data1 : 1, data2 : 2} on the load call, but I've had no success attaching jsondata. I've tried the following and a few variations of it and no luck. I'm using Extjs 2.2 w/ Alfresco
//creat开发者_Python百科e store
var memberStore = new Ext.data.JsonStore({
proxy : new Ext.data.HttpProxy({
url : url/getMembers,
method : 'POST'
}),
fields : ['username'],
root : 'members'
});
//function that loads store when it is called
function getMembers() {
memberStore.load({
//params : {action : "getmembers", groupname : "GROUP_Test"}
jsonData : {
action : "getmembers",
groupname : "GROUP_Test"
}
});
}
Instead of calling a store.load(), I created a function that would run an ajax request for the data. On a successfull callback, I would then load the store. Below is my code.
//create store
var memberStore = new Ext.data.JsonStore({
fields : ['username'],
root : 'members'
});
//function that loads store when it is called
function getMembers() {
var parameters = {
node : dynamicNodeId
}
Ext.Ajax.Request({
url : 'url/getMembers',
method : 'POST',
jsonData : Ext.encode(parameters),
success : function(response, opts) {
//decode json string
var responseData = Ext.decode(response.responseText);
//Load store from here
memberStore.loadData(responseData);
}
});
}//eo getMembers
You can do it this way.
Ext.apply(store.baseParams, { param1: '1', param2: '2'});
Ext.apply(store.proxy.conn, { jsonData: { data1: 'data1', data2: 'data2'} });
store.load();
The constructor for **HttpProxy**
takes a connection object. And Connection object understands **jsonData**
. So you can do this:
//create store
var memberStore = new Ext.data.JsonStore({
proxy : new Ext.data.HttpProxy({
url : url/getMembers,
method : 'POST',
//here is the change
jsonData: {data1 : 1, data2 : 2}
}),
fields : ['username'],
root : 'members'
});
//function that loads store when it is called
function getMembers() {
memberStore.load({
//params : {action : "getmembers", groupname : "GROUP_Test"}
jsonData : {
action : "getmembers",
groupname : "GROUP_Test"
}
});
}
You can use baseParams: { key: "value", key2: "value2" }
This should work with the store using both GET and POST.
精彩评论