-
13 May 2009 7:59 AM #1
[SOLVED] Help with DirectStore
[SOLVED] Help with DirectStore
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:
with server response:Code: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'} ] ) })
Code:{"totalCount":100,"users":[{"firstname":"Mo","lastname":"Smith","id":"9942418"},{"firstname":"Carlos","lastname" :"Tran","id":"9954769"}]}
I am replacing it with:
which returns:Code: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'} ] });
It seems like the error occurs in the Reader, not being able to understand the data.Code:{"type":"rpc","tid":2,"action":"TestAction","method":"getUsers","result":{"totalCount":100,"users":[ {"firstname":"Mo","lastname":"Smith","id":"9942418"},{"firstname":"Carlos","lastname":"Tran","id":"9954769" }]}}
If anyone has any ideas it would be greatly appreciated.
Thx
Dan
-
13 May 2009 8:27 AM #2
ok that was simple:
PHP Code:paramsAsHash: false,
-
15 May 2009 11:52 AM #3
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?
ThanksEugene
Ext.Direct for ASP.NET MVC
-
15 May 2009 4:58 PM #4
paramsAsHash takes all the parameters and sends them off as a JSON object.
paramOrder defines the order of the params to be sent, eg:
So it would be like calling the method:Code:{ foo: 1, bar: 'some value', baz: 3 } paramOrder: ['baz', 'foo', 'bar']
Code:Foo.MyMethod(3, 1, 'some value');
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
16 May 2009 7:59 AM #5
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.
Eugene
Ext.Direct for ASP.NET MVC
-
22 May 2009 1:25 AM #6
-
22 May 2009 10:51 AM #7
paramsAsHash is true by defaultCode: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); }
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: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})....Code:args.push(this.createCallback(action, reader, callback, scope, options)); directFn.apply(window, args);


Reply With Quote
