Ext js 6中模型之间的关联失败

时间:2016-11-11 04:42:54

标签: javascript extjs extjs5 extjs6

我正在研究一个小例子,以了解在Ext js 5中正常工作但在Ext js 6版本中失败的关联。

Ext.onReady(function() {

// parent model
Ext.define('Continent', {
    extend: 'Ext.data.Model',
    field: ['name'],
    hasMany: {
        model: 'Country',
        name: 'countries'
    }
});


//child model
Ext.define('Country', {
    extend: 'Ext.data.Model',
    field: ['name'],
    associations: [{
        type: 'belongsTo',
        model: 'Continent',
        associationKey: 'countries',
    }]
});

//created store for parent which contains child data
Ext.define('ContinentStore', {
    extend: 'Ext.data.Store',
    storeId: 'continent',
    model: 'Continent',
    autoLoad: true,
    proxy: {
        type: 'memory',
        data: [{
            name: 'Asia',
            countries: [{
                name: 'India'
            }, {
                name: 'Srilanka'
            }, {
                name: 'Bangladesh'
            }]
        }, {
            name: 'Africa',
            countries: [{
                name: 'Nigeria'
            }, {
                name: 'Kenya'
            }, {
                name: 'South Africa'
            }]
        }, {
            name: 'America',
            countries: [{
                name: 'West'
            }, {
                name: 'East'
            }, {
                name: 'South'
            }]
        }]
    }
});

var continentGrid = Ext.create('Ext.grid.Panel', {
    title: 'Continent Grid',
    store: Ext.create('ContinentStore'),
    width: '50%',
    height: '100%',
    listeners: {
        select: function(cmp, record, index) {
            //record.countries() will return new store.
            // to append new store I have used reconfigure method.
            Ext.getCmp('CountryGrid').reconfigure(record.countries());;
        }
    },
    columns: [{
        dataIndex: 'name',
        text: 'Continent',
        flex: 1
    }]
});
var countryGrid = Ext.create('Ext.grid.Panel', {
    title: 'Country  Grid',
    id: 'CountryGrid',
    width: '50%',
    height: '100%',
    columns: [{
        dataIndex: 'name',
        text: 'Country',
        flex: 1
    }]
});
Ext.create('Ext.window.Window', {
    width: 500,
    height: 400,
    layout: 'hbox',
    autoShow: true,
    items: [continentGrid, countryGrid]
})
//console.log(continent);

});

当我尝试在Ext js 6中运行示例时,verison低于错误。

  

未捕获错误:hasMany(“Continent”)和belongsTo(“Country”)不应同时用于声明relatedxtionship。只使用一个。(...)

工作fiddle

0 个答案:

没有答案