Results 1 to 4 of 4

Thread: Nested Model not loading hasmany

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Aug 2016
    Posts
    14
    Answers
    1

    Default Answered: Nested Model not loading hasmany

    Hi guys!!

    I'm having a little problem with nested models and, although I searched and followed a bunch of tutorials, I couldn't get it right.

    I have the following JSON that has 3 registers and the last one has one child.

    Code:
    {
        "data" : [{
                "iconCls" : "x-fa fa-desktop",
                "id" : 1,
                "leaf" : true,
                "parentId" : 0,
                "text" : "Trabalhos"
            }, {
                "iconCls" : "x-fa  fa-paper-plane",
                "id" : 2,
                "leaf" : true,
                "parentId" : 0,
                "text" : "E-mail"
            }, {
                "children" : [{
                        "iconCls" : "x-fa user",
                        "id" : 4,
                        "leaf" : true,
                        "parentId" : 3,
                        "text" : "Editar"
                    }
                ],
                "iconCls" : "x-fa fa-users",
                "id" : 3,
                "leaf" : false,
                "parentId" : 0,
                "text" : "Usuários"
            }
        ]
    }

    I made the following Models: Menu and MenuChild

    Menu
    Code:
    Ext.define('PlataformaFluxo.model.menu.Menu', {
        extend: 'Ext.data.Model',
    
        requires: [
            'PlataformaFluxo.model.menu.MenuChild'
        ],
    
        fields: ['id', 'text', 'iconCls','leaf', 'parentId'],
    
        hasMany: {
            model: 'PlataformaFluxo.model.menu.MenuChild',    
            name: 'children',
            associationKey: 'children'
        },
        
        proxy:{
            type: 'ajax',
            url:'treelistMenu.action',
            noCache: false,
            reader:{
                type: 'json',
                rootProperty: 'data'
            }
        }
        
    });

    MenuChild:
    Code:
    Ext.define('PlataformaFluxo.model.menu.MenuChild', {
        extend: 'Ext.data.Model',
    
        fields: ['id', 'text', 'iconCls', 'leaf', 'parentId']
        
    });

    Sencha loads fine the 3 registers, but it doesn't get the children from the last one (childNodes remains empty).

    What I am doing wrong?


    Thanks!!

  2. I found out!

    The associationKey and name had the same value and that was, somehow, messing with everything!

Similar Threads

  1. Loading nested XML data into hasmany model
    By mjankela in forum Ext: Q&A
    Replies: 3
    Last Post: 22 Mar 2015, 6:22 PM
  2. Loading nested XML data into hasmany model
    By mjankela in forum Community Discussion
    Replies: 0
    Last Post: 14 Mar 2015, 7:16 AM
  3. AJAX Store & loading data from nested hasMany association
    By kitesurf in forum Sencha Touch 2.x: Q&A
    Replies: 3
    Last Post: 10 Feb 2014, 11:32 AM
  4. Children elements aren't show using nested json, Model and hasMany association.
    By dusoft in forum Sencha Architect 2.x: Help & Discussions
    Replies: 2
    Last Post: 18 Jul 2013, 11:33 AM
  5. Model with nested hasmany, empties child record on model.load(
    By salorob in forum Sencha Touch 2.x: Q&A
    Replies: 3
    Last Post: 18 Aug 2012, 1:24 AM

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
  •