Pergunta

I want to add the associations on model based on the value of a field. For example:

I want to add associations like

Parent Model:

Ext.define('App.model.parentModel', {
    extend: 'Ext.data.Model',
    requires: [
        'App.model.ChildModel1',
        'App.model.ChildModel2',
    ],
    idProperty: 'type',
    fields: [
        'name',
        'type'
    ],
proxy:[//proxy]
});

I want to add associations like

hasMany:{
model:'App.model.ChildModel1' 
}

if my value for 'type' field is automobile.

Else I want to add associations like

hasMany:{
model:'App.model.ChildModel2' 
}

How can I check this on fly and add associations?

Foi útil?

Solução

Two approaches come to my mind.

The first thing you can try is use the model's setFields() method. I have never used this method before, but according to the docs it looks like it could satisfy what you are looking for. An example can be found here: http://www.sencha.com/forum/showthread.php?189160-Ext.data.Model-setFields-not-Working-as-Expected

--OR--

Something I have done in the past is create 2 stores that use 'App.model.ChildModel1' and the other uses 'App.model.ChildModel2'. Then you can use reconfigure() on the panel/grid and give it the store appropriately.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top