Results 1 to 9 of 9

Thread: DirectStore confusion

  1. #1
    Ext JS Premium Member Lloyd K's Avatar
    Join Date
    Oct 2007
    Location
    Brighton, United Kingdom
    Posts
    655
    Vote Rating
    1
      0  

    Default 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:

    Code:
    {"type":"rpc","tid":2,"action":"Session","method":"getLanguages","result":"{\"count\":1,\"list\":[{\"lang_id\":\"en_GB\",\"lang_name\":\"English\"}]}"}
    My problem is, how do I tell a ComboBox to use this for its store?
    The store is defined as:

    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"
                        }
                    }),
    Interestingly result is infact a string and not proper JSON, perhaps it's down to the .NET stack that's been done?
    - Lloyd K

    I blog about code from time to time: http://codeology.lloydkinsella.net/

  2. #2
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,487
    Vote Rating
    145
      0  

    Default

    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

  3. #3
    Ext JS Premium Member Lloyd K's Avatar
    Join Date
    Oct 2007
    Location
    Brighton, United Kingdom
    Posts
    655
    Vote Rating
    1
      0  

    Default

    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 :/
    - Lloyd K

    I blog about code from time to time: http://codeology.lloydkinsella.net/

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,369
    Vote Rating
    858
      0  

    Default

    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!

  5. #5
    Ext JS Premium Member Lloyd K's Avatar
    Join Date
    Oct 2007
    Location
    Brighton, United Kingdom
    Posts
    655
    Vote Rating
    1
      0  

    Default

    I'm not at work so a bit of a pain to explain, but its like in the example:

    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);
            }
    The only difference is I'm using DirectMethod and not DirectMethodForm.
    - Lloyd K

    I blog about code from time to time: http://codeology.lloydkinsella.net/

  6. #6

  7. #7
    Ext JS Premium Member randomY's Avatar
    Join Date
    Apr 2007
    Location
    Katy, Texas
    Posts
    14
    Vote Rating
    0
      0  

    Default

    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.

    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                   })
    loads with ArrayReader:
    Code:
    {
      "type":"rpc",
      "tid":9,
      "action":"ProjectSequence",
      "method":"listsequences",
      "result":[
        ["2009106"],
        ["2009107"],
        ["2009108"]
      ]
    }
    wouldn't load with JsonReader:
    Code:
    {
      "type":"rpc",
      "tid":9,
      "action":"ProjectSequence",
      "method":"listsequences",
      "result":[
        {"project":"2009106"},
        {"project":"2009107"},
        {"project":"2009108"}
      ]
    }

  8. #8
    Sencha User
    Join Date
    Dec 2008
    Location
    Mainz
    Posts
    241
    Vote Rating
    1
      0  

    Default

    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...

  9. #9
    Ext JS Premium Member Lloyd K's Avatar
    Join Date
    Oct 2007
    Location
    Brighton, United Kingdom
    Posts
    655
    Vote Rating
    1
      0  

    Default

    I'll check it out, that's what I'm looking for, direct JSON output with no magic inbetween
    - Lloyd K

    I blog about code from time to time: http://codeology.lloydkinsella.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •