使用hasMany关系加载模型/商店?

时间:2013-07-08 16:54:17

标签: sencha-touch-2

我正在尝试为一个基本家庭建模,那里有一个母亲和父亲,零个或多个孩子。我想我明白如何定义这两个模型(家庭和儿童)。但是,我对如何定义Store(或TreeStore?)并实际加载数据有点不清楚。


    [
        {
            "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"
                }
            ]
        }
    ]

家庭模式:


    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);
        }
    });

儿童模特:


    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 个答案:

答案 0 :(得分:0)

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

    config: {

STOREID: 'Familystore', 型号: 'SF.model.Family' });

在列表中,您可以将商店作为storeid'Familystore'