PDA

View Full Version : How to pass JSon parameter to Ext.data.Store?



Limbo
18 Jul 2011, 7:45 AM
I have this code:

myCompanyStore = new Ext.data.Store({
model: 'CompanyList',
storeID: 'myCompanyStore',
autoLoad: true,
proxy:
{
headers:
{
'Content-Type': 'application/json; charset=utf-8'
},
url: 'Default.aspx/GetCompanyCollection',
type: 'ajax',
limitParam: null,
actionMethods:
{
read: 'POST'
},
reader:
{
type: 'json',
root: 'd'
},
extraParams:
{
argCurrentNavisionUserId: $("#hfCurrentNavisionUserId").val()
}
}
});

Parameter is passed, but it doesn't work, because it's passed in plain text, I believe. Says:

argCurrentNavisionUserId=value

In the debugger. How can I pass this as Json? without the datastore, I use jsonData instead of extraParams, which works. But this does not work with the Store :/

Suggestions?

Limbo
19 Jul 2011, 10:22 AM
Noone has any idea? :/

Limbo
2 Jan 2012, 6:01 AM
I am running into this again. How can I pass parameters with the store proxy?

Limbo
4 Jan 2012, 7:32 AM
Let me answer this, for the sake of the community :)

Change the .NET code to:

[WebMethod()]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]

To change the method, so it can be called using GET.

Set the parameter like this, before loading the store:

var extraParams = myContactInfoStore.getProxy().extraParams.argUserRecID = argUserRecID;
myContactInfoStore.load();

This will add the UserRecID to the querystring, which wil be passed to the .NET method, if you need to do it dynamically.

Hope this will help someone.