Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs 使用同一模型是否可能有多个HAS和多个关系?_Extjs_Sencha Touch_Sencha Touch 2 - Fatal编程技术网

Extjs 使用同一模型是否可能有多个HAS和多个关系?

Extjs 使用同一模型是否可能有多个HAS和多个关系?,extjs,sencha-touch,sencha-touch-2,Extjs,Sencha Touch,Sencha Touch 2,我有一种情况,我有一个模型,用于存储多个化学品列表。每个都有许多关系,化学模型是相同的 我需要这样的东西: Ext.define('HandSurvey.model.ChemicalRisks', { extend: 'Ext.data.Model', requires: ['Ext.data.identifier.Uuid'], config: { idProperty: 'id', identifier: 'uuid',

我有一种情况,我有一个模型,用于存储多个化学品列表。每个
都有许多
关系,化学模型是相同的

我需要这样的东西:

Ext.define('HandSurvey.model.ChemicalRisks', {
    extend: 'Ext.data.Model',
    requires: ['Ext.data.identifier.Uuid'],
    config: {
        idProperty: 'id',
        identifier: 'uuid',
        fields: [
            { name: 'id', type: 'auto' }
        ],
        associations: [
            {
                type: 'hasMany',
                model : 'HandSurvey.model.SpecificChemical',
                name  : 'fiberglassResins',
                store : {
                    type: 'sql'
                }
            },
            {
                type: 'hasMany',
                model : 'HandSurvey.model.SpecificChemical',
                name  : 'paintsStains',
                store : {
                    type: 'sql'
                }
            },
        ],
        proxy: {
            type: 'sql'
        }
    }
});
但这将导致每个列表绑定到属于
化学风险
模型的每个
特定化学品
,而不仅仅是那些属于该
模型的化学品。似乎我需要在多个领域加入


有可能这样做吗?或者我必须用不同的名称制作一串完全相同的型号/商店吗?

当然可以

使用associationKey和自动生成的关联存储

associations: [
            {
                type: 'hasMany',
                model : 'HandSurvey.model.SpecificChemical',
                name  : 'fiberglassResins',
                associationKey : 'fiberglassResins'
            },
            {
                type: 'hasMany',
                model : 'HandSurvey.model.SpecificChemical',
                name  : 'paintsStains',
                associationKey : 'paintsStains'
            },
        ]
给出如下响应:{

    "response" : {
        "fiberglassResins": [
            {
                "id"   : 1
                "name" : "Polyester"

            },
            {
                "id"   : 2
                "name" : "E-Glass"
            }

        ],
        "paintsStains": [
            {
                "id"   : 1
                "name" : "item1"

            },
            {
                "id"   : 2
                "name" : "item2"
            }

        ]
    }
}
然后将主模型绑定到商店,比如ItemsStore。 重要信息:每个ItemsStore记录将由Sencha自动生成:FiberGrassResinsStore和PaintsStansStore。

您可以通过console.log()来查看每个记录的实际存储