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 firekesti's Avatar
    Join Date
    Sep 2012
    Posts
    22
    Answers
    2
    Vote Rating
    1
    firekesti is on a distinguished road

      0  

    Default Answered: fun with arrays in JSON

    Answered: fun with arrays in JSON


    Hey community. I haven't been able to figure out how to access part of a piece of data loaded from a store. Here's the JSON:

    Code:
    entity-list:
    {
        "id":"1e3f2071638241e292b705c034be4d6b",
            "title": "Planets",
        "entities":
        {
            "data":
            [
                {
                    "data":
                    {
                        "name":"Earth",
                        "id":"23f03fe70a16aed0d7e210357164e401",
                        }
                    }
                },
                {
                    "data":
                    {
                        "name":"Moon",
                        "id":"23f03fe70a16aed0d7e210357164e339",
                    }
                }
    
    
            ]
        }
    }
    For the id, title (and other properties omitted here), it's simple, and I get that.
    Code:
        config: {
            fields: [
            { name: 'id', type: 'string' },
            { name: 'title', type: 'string' },
            ...etc
            ]
        }
    But I'm not sure how to get the "name" part of each of the entities in the list. I've tried several things:

    Code:
            { name: 'entities', mapping: 'entities.data.data' }, //or entities.data
    Code:
            hasMany: [
            { name: 'entities', model: 'KT.model.Entity', associationKey: 'entities' }, //or entities.data
            ]

    For what it's worth, the Entity model looks like this:
    Code:
    Ext.define('KT.model.Entity', {
        extend: 'Ext.data.Model',
    
    
        config: {
            fields: [ 
            { name: 'id', type: 'string' },
            { name: 'name', type: 'string' },
            ]
        }
    });
    What am I missing?

  2. I so understand, I never managed to use the associations for models

    After several hours of struggling, I decided to explore the data using a DOM debugger (like the one in Safari or Chrome) and use the complete "address" of the data, which can gives something like this :

    Code:
    Ext.getStore('myStore').getAt(0).data.foo[2].bar[1].value
    Dirty but working . If you can get hasMany to work it is much better of course.

  3. #2
    Sencha User firekesti's Avatar
    Join Date
    Sep 2012
    Posts
    22
    Answers
    2
    Vote Rating
    1
    firekesti is on a distinguished road

      0  

    Default


    Code:
    { name: 'entities',         mapping: 'entities.data[0].data["name"]' },
    This code works well to give me exactly what I need from one of the elements, but not both - I feel like I should be using hasMany, but not sure how. This is the furthest I've gotten

  4. #3
    Sencha User siebmanb's Avatar
    Join Date
    Aug 2011
    Location
    Geneva (CH) - Grenoble (FR)
    Posts
    253
    Answers
    11
    Vote Rating
    15
    siebmanb will become famous soon enough

      0  

    Default


    I so understand, I never managed to use the associations for models

    After several hours of struggling, I decided to explore the data using a DOM debugger (like the one in Safari or Chrome) and use the complete "address" of the data, which can gives something like this :

    Code:
    Ext.getStore('myStore').getAt(0).data.foo[2].bar[1].value
    Dirty but working . If you can get hasMany to work it is much better of course.
    Twitter account @siebmanb.
    Co-founder & CEO at ButterflyEffect.
    Mobile application developer using Sencha Touch and Phonegap for iOS, Android and webapp.

  5. #4
    Sencha User firekesti's Avatar
    Join Date
    Sep 2012
    Posts
    22
    Answers
    2
    Vote Rating
    1
    firekesti is on a distinguished road

      0  

    Default


    Thanks, I suppose I'll try that out perhaps using 'each' to get all the values, since there is a varying amount across instances of the model. In the meantime, I also have to figure out how to do 'hasOne' for an element that I have to do an additional query for.

  6. #5
    Sencha User siebmanb's Avatar
    Join Date
    Aug 2011
    Location
    Geneva (CH) - Grenoble (FR)
    Posts
    253
    Answers
    11
    Vote Rating
    15
    siebmanb will become famous soon enough

      0  

    Default


    One last trick : even if your model does not contain the right entries, most of the time the parameter "raw" in the callback response contains the data you are looking for. Dirty but efficient
    Twitter account @siebmanb.
    Co-founder & CEO at ButterflyEffect.
    Mobile application developer using Sencha Touch and Phonegap for iOS, Android and webapp.

  7. #6
    Sencha User firekesti's Avatar
    Join Date
    Sep 2012
    Posts
    22
    Answers
    2
    Vote Rating
    1
    firekesti is on a distinguished road

      0  

    Default


    Hmm, what if I have a setup like this: a REST call gives me a list of 'entity' models which all work fine. But then, inside each 'entity' model is a 'body' link. The data for it is at '/entity/{id}/body' and I don't know if I should be using a hasOne for this or just some weird custom proxy stuff. The body should be part of the entity, but requires a separate call to be so.

  8. #7
    Sencha User siebmanb's Avatar
    Join Date
    Aug 2011
    Location
    Geneva (CH) - Grenoble (FR)
    Posts
    253
    Answers
    11
    Vote Rating
    15
    siebmanb will become famous soon enough

      0  

    Default


    I am not sure I understand. Are you asking if you should send all the entities together, or have a separate call to get the ones you want ?
    Twitter account @siebmanb.
    Co-founder & CEO at ButterflyEffect.
    Mobile application developer using Sencha Touch and Phonegap for iOS, Android and webapp.

  9. #8
    Sencha User firekesti's Avatar
    Join Date
    Sep 2012
    Posts
    22
    Answers
    2
    Vote Rating
    1
    firekesti is on a distinguished road

      0  

    Default


    I'm using a RESTful api, so it does require another call to get certain elements. It's ok though, I found https://github.com/mhorner/RestModel and it looks like that will work a lot better for me. Thanks so much for your help though!

  10. #9
    Sencha User siebmanb's Avatar
    Join Date
    Aug 2011
    Location
    Geneva (CH) - Grenoble (FR)
    Posts
    253
    Answers
    11
    Vote Rating
    15
    siebmanb will become famous soon enough

      0  

    Default


    I believe doing another call is not always a bad idea : that way you don't get unnecessary data at first and the request stays light.

    Good luck.
    Twitter account @siebmanb.
    Co-founder & CEO at ButterflyEffect.
    Mobile application developer using Sencha Touch and Phonegap for iOS, Android and webapp.

Thread Participants: 1

Tags for this Thread