Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
    jogjayr is on a distinguished road

      0  

    Default Answered: Nested JSON and hasMany associations

    Answered: Nested JSON and hasMany associations


    My server returns data that's something like the following:

    UPDATE: my server is returning arrays of objects. neglected to mention that

    Code:
    [
       {    
           "parentId": "a",
           "prop1": "asda",
            "childItems": [
                 {
                     "childId": "3",
                      "prop2": "aqqr"
                 },
                 {
                      "childId": "4",
                       "prop2": "aaqr"
                 }
             ]
         },
      {    
           "parentId": "b",
           "prop1": "kkhj",
            "childItems": [
                 {
                     "childId": "4",
                      "prop2": "ohc"
                 },
                 {
                      "childId": "5",
                       "prop2": "diih"
                 }
             ]
         }
    ]
    For this I have the following models:

    Code:
    Ext.define("Parent", {
         extend: "Ext.data.Model",
         config: {
               fields: ["id", "prop1"],
               hasMany: {model: "Child", name: "childItems"}
         }
    });
    and
    Code:
    Ext.define("Child", {
        extend: "Ext.data.Model",
        config: {
            fields: ["id", "prop2"],
            belongsTo: {model: "Parent"}
        }
    });
    and the store for the parent objects

    Code:
    Ext.define("Parents", {
             extend: "Ext.data.Store",
             requires: "Parent"
           config: {
                       model: "Parent",
                       autoLoad: true,
                       proxy: {
                                  type: "ajax",
                                  url: "getparents.php",
                                  reader: {
                                            type: "json",
                                            idProperty: "parentId"
                                  }
                       }
             }
    });
    The problem I have is that all the properties of the Parent object get loaded, but the reader doesn't seem to parse the Child objects from the JSON into Child objects that are then loaded into the Parent object. That is to say, the hasMany association doesn't work with the JSON Proxy. Am I doing something wrong?
    Last edited by jogjayr; 6 Feb 2012 at 9:47 AM. Reason: code wasn't formatted

  2. Found it. Had to use the associationKey config value for the hasMany association.

    There is a great example for this in the Beta 1 docs (Ext.data.reader.Reader). I was previously referring to the PR4 docs since the online docs don't work for me for some reason (a Javascript error that appears every time).

    Thanks for the help

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,519
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Your store is expecting an array and looks like you are giving it an Object. You may also want to look at primaryKey
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Nov 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
    jogjayr is on a distinguished road

      0  

    Default


    My server is returning arrays. I just didn't report it correctly here in the post. Updated my initial post to reflect this.

    I tried

    Code:
    primaryKey: "childId"
    in the hasMany association. This doesn't really seem to have changed anything. The Parent items from the Parent store still have an empty "childItems" array.

  5. #4
    Sencha User
    Join Date
    Nov 2010
    Posts
    10
    Answers
    1
    Vote Rating
    0
    jogjayr is on a distinguished road

      0  

    Default


    Found it. Had to use the associationKey config value for the hasMany association.

    There is a great example for this in the Beta 1 docs (Ext.data.reader.Reader). I was previously referring to the PR4 docs since the online docs don't work for me for some reason (a Javascript error that appears every time).

    Thanks for the help

Thread Participants: 1

Tags for this Thread