View Full Version : DirectStore confusion

Lloyd K
15 May 2009, 6:49 AM
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?
The store is defined as:

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"

Interestingly result is infact a string and not proper JSON, perhaps it's down to the .NET stack that's been done?

15 May 2009, 8:32 AM
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.

Lloyd K
15 May 2009, 10:30 AM
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
Under the hood it's using JSON.NET, so it depends on what type you're returning.

Lloyd K
16 May 2009, 5:56 AM
I'm not at work so a bit of a pain to explain, but its like in the example:

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);

The only difference is I'm using DirectMethod and not DirectMethodForm.

26 Oct 2009, 6:24 AM
Same problem!!


26 Oct 2009, 11:32 AM
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.

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 })loads with ArrayReader:

}wouldn't load with JsonReader:


26 Oct 2009, 11:15 PM
For this Situation my implementation of the Direct ServerStack (http://www.extjs.com/forum/showthread.php?t=68619) 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...

Lloyd K
30 Oct 2009, 6:05 AM
I'll check it out, that's what I'm looking for, direct JSON output with no magic inbetween :)