Results 1 to 3 of 3

Thread: Children elements aren't show using nested json, Model and hasMany association.

  1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    27

    Default Children elements aren't show using nested json, Model and hasMany association.

    Hello! I am going crazy!!

    I did a simple sencha touch app, using a nested json file, list component, xTemplate and a "Model" with HasOne (Works fine!) and HasMany associations (Doesn't work)....


    JSON:
    Code:
    [{
        "Codigo": "1",
        "Nombre": "Model 1",
        "SubModel": {
            "Codigo": "2",
            "Nombre": "SubModel 2"
        },
        "Coleccion": [
                {
                    "Cod": "4",
                    "Descripcion": "Four"
                },
                {
                    "Cod": "5",
                    "Descripcion": "Five"
                }
     ]
    },
    {
        "Codigo": "2",
        "Nombre": "Model 2",
        "SubModel": {
            "Codigo": "3",
            "Nombre": "SubModel 3"
        },
        "Coleccion": [
                {
                    "Cod": "6",
                    "Descripcion": "Six"
                },
                {
                    "Cod": "7",
                    "Descripcion": "seven"
                }
     ]
    } 
    ]

    MODELS:

    Code:
    Ext.define('MyApp.model.Modelo', {
        extend: 'Ext.data.Model',
    
    
        uses: [
            'MyApp.model.SubModel',
            'MyApp.model.Coleccion'
        ],
    
    
        config: {
            fields: [
                {
                    name: 'Codigo',
                    type: 'string'
                },
                {
                    name: 'Nombre',
                    type: 'string'
                }
            ],
            hasOne: {
                name: 'SubModel',
                associationKey: 'SubModel',
                model: 'MyApp.model.SubModel'
            },
            hasMany: {
                associationKey: 'Coleccion',
                model: 'MyApp.model.Coleccion',
                name: 'Coleccion'
            }
        }
    });
    Code:
    Ext.define('MyApp.model.Coleccion', {
        extend: 'Ext.data.Model',
    
    
        config: {
            fields: [
                {
                    name: 'Cod',
                    type: 'string'
                },
                {
                    name: 'Descripcion',
                    type: 'string'
                }
            ],
            belongsTo: {
                model: 'MyApp.model.Coleccion'
            }
        }
    });
    Code:
    Ext.define('MyApp.model.SubModel', {
        extend: 'Ext.data.Model',
    
    
        uses: [
            'MyApp.model.Modelo'
        ],
    
    
        config: {
            fields: [
                {
                    name: 'Codigo',
                    type: 'string'
                },
                {
                    name: 'Nombre',
                    type: 'string'
                }
            ],
            belongsTo: {
                model: 'MyApp.model.Modelo'
            }
        }
    });
    VIEW:

    Code:
    Ext.define('MyApp.view.MyList', {
        extend: 'Ext.dataview.List',
    
    
        config: {
            store: 'MyJsonStore',
            itemTpl: [
                '<b>{Codigo} - {Nombre} </b>',
                '<div>',
                '<h2>{SubModel.Nombre}</h2>',
                '    <tpl for="Coleccion">',
                '        <h3>{Cod}-{Descripcion}</h3>',
                '    </tpl>   ',
                '</div>'
            ]
        }
    
    
    });
    It is happening:


    a) In the architect preview windows, the children (HasMany) aren't show..
    ArchitectPreview.png
    b) In the chrome preview, the children (HasMany) aren't show but you can see that they are loaded in the console debug windows.
    ChromePreview-1.png
    c) In the SAME chrome preview, I play with the refresh button (F5) and.... they are show, press refresh button again, and they aren't show...Strange!!
    ChromePreview-2.png


    I attached the architect project and the test evidence with the description of the issue.

    I am using Architect 2.2.2 991 and Sencha touch 2.2.1 . (Latest version) .

    Please, can I help me?

    Best Regards!
    Attached Files Attached Files

  2. #2
    Sencha User
    Join Date
    Jan 2009
    Location
    Frederick, Maryland
    Posts
    925

    Default

    Just taking a cursory look, your associationKey doesn't look correct to me.

    http://docs.sencha.com/touch/2.2.1/#...associationKey

  3. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    27

    Default

    Thanks for your response, but I don't understand how to use the ussociationKey in the Nested Json?
    I Thought that the associationKey is the "Node Name" of the collections of items in the nested Json. It's works for the HasOne association , but not in the HasMany.. Can you provide a simple example? or modified my attached solution..Please?

    I used the "associationKey" with the same criteria that this POST. (See best answer)
    http://www.sencha.com/forum/showthread.php?185254-Nested-JSON-and-hasMany

    Thanks!!

Tags for this Thread

Posting Permissions

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