-
15 May 2009 6:49 AM #1
DirectStore confusion
DirectStore confusion
I'm trying out DirectStore today and I'm confused. I have my Store requesting and returning just fine, however it returns this:
My problem is, how do I tell a ComboBox to use this for its store?Code:{"type":"rpc","tid":2,"action":"Session","method":"getLanguages","result":"{\"count\":1,\"list\":[{\"lang_id\":\"en_GB\",\"lang_name\":\"English\"}]}"}
The store is defined as:
Interestingly result is infact a string and not proper JSON, perhaps it's down to the .NET stack that's been done?Code:store: new Ext.data.DirectStore({ autoLoad: true, directFn: Session.getLanguages, paramsAsHash: false, idProperty: 'lang_id', fields: [ {name: "lang_id", type: "string"}, {name: "lang_name", type: "string"} ], sortInfo: { field: "lang_name", direction: "ASC" } }),
-
15 May 2009 8:32 AM #2
Looks like the result is getting double encoded. You should be returning your object directly from the language of your choice (.NET) rather than encoding it yourself. Also taking a look at the above code, it looks like you forgot to set root: 'list' in your store config.
Aaron Conran
@aconran
Sencha Architect Development Team
-
15 May 2009 10:30 AM #3
Yeh I set root soon after. I'm not encoding it I'm simply creating JObject like in the example but it seems it is getting double encoded :/
-
15 May 2009 4:30 PM #4
Under the hood it's using JSON.NET, so it depends on what type you're returning.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
16 May 2009 5:56 AM #5
I'm not at work so a bit of a pain to explain, but its like in the example:
The only difference is I'm using DirectMethod and not DirectMethodForm.Code:[DirectMethodForm] public string SaveForm(HttpRequest request) { int age = 0; int.TryParse(request["age"], out age); JObject o = new JObject( new JProperty("firstName", request["firstName"]), new JProperty("lastName", request["lastName"]), new JProperty("age", age)); return o.ToString(Newtonsoft.Json.Formatting.None); }
-
26 Oct 2009 6:24 AM #6
-
26 Oct 2009 11:32 AM #7
I struggled with this too, finally gave up. Never got it to load with a JsonReader. Did get it to load by returning an array of arrays and using an ArrayReader.
loads with ArrayReader:Code:105 store: new Ext.data.DirectStore({ 106 directFn: ProjectSequence.listsequences, 107 paramsAsHash: false, 108 autoDestroy: true, 109 mode: 'remote', 110 writer: new Ext.data.JsonWriter({encode: false}), 111 reader: new Ext.data.ArrayReader({fields: ['sequence']}), 112 paramOrder: ['query'] 113 })
wouldn't load with JsonReader:Code:{ "type":"rpc", "tid":9, "action":"ProjectSequence", "method":"listsequences", "result":[ ["2009106"], ["2009107"], ["2009108"] ] }
Code:{ "type":"rpc", "tid":9, "action":"ProjectSequence", "method":"listsequences", "result":[ {"project":"2009106"}, {"project":"2009107"}, {"project":"2009108"} ] }
-
26 Oct 2009 11:15 PM #8
For this Situation my implementation of the Direct ServerStack has an Attribute parameter called "Outputhandling" which you can set to "JSON" to disable central json serialization... Maybe this could make it into the official Extjs serverstack to avoid those traps...
-
30 Oct 2009 6:05 AM #9
I'll check it out, that's what I'm looking for, direct JSON output with no magic inbetween



Reply With Quote