PDA

View Full Version : [SOLVED] Help with DirectStore



vinnybozz
13 May 2009, 7:59 AM
Hi, I am trying to convert an existing Store using an HttpProxy and JsonReader to a DirectStore ...

I just can't seem to make it work, here's a sample of my json store:


var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
method: 'POST',
url: 'ajax/get-users.php',
timeout: 120000
}),
reader: new Ext.data.JsonReader({
root: 'users',
totalProperty: 'totalCount'
},
[
{name: 'firstname', mapping: 'firstname'},
{name: 'lastname', mapping: 'lastname'},
{name: 'id', mapping: 'id'}
]
)
})

with server response:

{"totalCount":100,"users":[{"firstname":"Mo","lastname":"Smith","id":"9942418"},{"firstname":"Carlos","lastname"
:"Tran","id":"9954769"}]}


I am replacing it with:


var store = new Ext.data.DirectStore({
directFn: TestAction.getUsers,
paramsAsHash: true,
root: 'users',
totalProperty: 'totalCount',
idProperty: 'id',
fields: [
{name: 'firstname', mapping: 'firstname'},
{name: 'lastname', mapping: 'lastname'},
{name: 'id', mapping: 'id'}
]
});

which returns:

{"type":"rpc","tid":2,"action":"TestAction","method":"getUsers","result":{"totalCount":100,"users":[
{"firstname":"Mo","lastname":"Smith","id":"9942418"},{"firstname":"Carlos","lastname":"Tran","id":"9954769"
}]}}

It seems like the error occurs in the Reader, not being able to understand the data.

If anyone has any ideas it would be greatly appreciated.

Thx
Dan

vinnybozz
13 May 2009, 8:27 AM
ok that was simple:


paramsAsHash: false,

elishnevsky
15 May 2009, 11:52 AM
I had the same issue, setting paramsAsHash to false solved it. But I still don't understand exactly what it does. It's not very clear from the docs. Can anyone explain this config option better?
Thanks

evant
15 May 2009, 4:58 PM
paramsAsHash takes all the parameters and sends them off as a JSON object.

paramOrder defines the order of the params to be sent, eg:



{
foo: 1,
bar: 'some value',
baz: 3
}

paramOrder: ['baz', 'foo', 'bar']


So it would be like calling the method:



Foo.MyMethod(3, 1, 'some value');

elishnevsky
16 May 2009, 7:59 AM
Ok, that's pretty clear. But what if a method had no arguments, like in my case? Setting paramsAsHash:true doesn't display the data in my GridPanel, although the data is coming back.

tuxhero
22 May 2009, 1:25 AM
Can u show some example

paramsAsHash takes all the parameters and sends them off as a JSON object.

paramOrder defines the order of the params to be sent, eg:



{
foo: 1,
bar: 'some value',
baz: 3
}

paramOrder: ['baz', 'foo', 'bar']


So it would be like calling the method:



Foo.MyMethod(3, 1, 'some value');

ficeto
22 May 2009, 10:51 AM
if(this.paramOrder){
for(var i = 0, len = this.paramOrder.length; i < len; i++){
args.push(params[this.paramOrder[i]]);
}
}else if(this.paramsAsHash){
args.push(params);
}
paramsAsHash is true by default
paramOrder is undefined
so when you put paramsAsHash:false, you don't add the parameters(limit, start ...) to the arguments(which are []).later on this happens:
args.push(this.createCallback(action, reader, callback, scope, options));
directFn.apply(window, args);
which adds object after all the arguments and that is the point where it all goes bad and does not load the request. I moved things around to add the arguments after that object and things show up, but the arguments still don't pass to the directFn (regardless of the form of arguments [arg1,arg2] or {arg1:val1,arg2:val2})....