1
votes

I'm trying to model a basic family where there is a mother and father with zero or more children. I think I understand how to defined the two models (Family and Children). However, I'm a little unclear on how I should defined the Store (or TreeStore?) and actually load the data.


    [
        {
            "father": "Donald Duck",
            "mother": "Mrs Duck",
            "children": [
                {
                    "fullname": "Huey",
                    "gender": "m"
                },
                {
                    "fullname": "Dewey",
                    "gender": "m"
                },
                {
                    "fullname": "Louie",
                    "gender": "m"
                }
            ]
        },
        {
            "father": "Mickey Mouse",
            "mother": "Mrs Mouse",
            "children": [
                {
                    "fullname": "Mickey Mouse, Jr.",
                    "gender": "m"
                }
            ]
        }
    ]

Family Model:


    Ext.define('SF.model.Family', {
        extend: 'Ext.data.Model',

        config: {
            fields: [
                {name: 'father', type:'string'},
                {name: 'mother', type:'string'}
                ],
                hasMany: {model: 'Children', name: 'children'}
        },
        load: function() {
            this.callParent(arguments);
        }
    });

Children Model:


    Ext.define('SF.model.Children', {
        extend: 'Ext.data.Model',

        config: {
            fields: [
                {name: 'fullname', type:'string'},
                {name: 'gender', type:'string'}
                ]
        },
        load: function() {
            this.callParent(arguments);
        }
    });

1

1 Answers

0
votes

Ext.define('SF.store.Family, 'extend: 'Ext.data.Model',

    config: {

Storeid:'Familystore', Model:'SF.model.Family' });

In list you can give the store as storeid 'Familystore'