0
demoAlerts({
    itemstatus: [
        {
            item: "1",
            name: "apple",
            type: "fruit"
        },
        {
            item: "2",
            name: "pine",
            type: "fruit"
        }
    ],
    deliverystatus: [
        {
            name: "james",
            status: "yes"
        },
        {
            name: "thomas",
            status: "no"
        },

    ]
});

I have two array (itemstatus and deliverystatus), I need to create the model for this store. what I tried is

ParentModel:

Ext.define('test.model.ParentModel', {
    extend: 'Ext.data.Model',
    requires:['test.model.ItemModel','test.model.DeliveryModel'],
autoLoad: true,
    config : {
    fields : [ 'itemstatus', {
        name : 'demostatuslist',
        model : 'demoAlerts.model.ItemModel',
        mapping : 'itemstatus'
    },
     'portalstatus', {
            name : 'deliverystatus',
            model : 'test.model.DeliveryModel',
            mapping : ' deliverystatus'
        }]
    }

});

ItemModel

Ext.define('demoAlerts.model.ItemModel', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            { name: 'item', type: 'string' },
            { name: 'name', type: 'string' },
            { name: 'type', type: 'string' }

        ]
    }
});

DeliveryModel

Ext.define('demoAlerts.model.DeliveryModel', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            { name: 'name', type: 'string' },
            { name: 'status', type: 'string' },


        ]
    }
});

Whether i properly configured the model. I am receiving the store as empty

2 Answers 2

1

Use Associations :) http://docs.sencha.com/touch/2.3.1/#!/api/Ext.data.association.Association

In this case I would have a Model with 2 hasMany associations like this:

Ext.define('demoAlerts.model.ContainerModel', {
    extend : 'Ext.data.Model',
    requires : [
        'demoAlerts.model.DeliveryModel',
        'demoAlerts.model.ItemModel'
    ],
    config : {
        associations: [
            {
                type           : 'hasMany',
                model          : 'demoAlerts.model.DeliveryModel',
                associationKey : 'deliveryStatus',
                name           : 'deliveryStatus',
                autoLoad       : true // this is very important
            },
            {
                type           : 'hasMany',
                model          : 'demoAlerts.model.ItemModel',
                associationKey : 'itemStatus',
                name           : 'itemStatus',
                autoLoad       : true // this is very important
            }
        ]
    }
});

Then use a store SomeStore binded to ContainerModel.

IMPORTANT Each record in SomeStore will have deliveryStatusStore and itemStatusStore AUTOGENERATED.

Read about associations.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks man its working. Now i got clear idea about association. :)
0

Neither http://docs.sencha.com/touch/2.3.1/#!/api/Ext.data.Field nor http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.data.field.Field

knows a valid config option "model" for a field.

  • As far as I know, there is no such thing as a "Parent Model" available in ExtJS or Sencha Touch.
  • As far as I know, there is no possibility to have two stores in one.

You can load two (or more) stores using only one call to the server like in my following example:

firststore.on('load',function() {
    secondstore.loadRawData(firststore.getProxy().getReader().rawData);
});
firststore.load()

Where you would give firststore the server url and the root of the data that goes into the first store, and secondstore will have the root of the data that goes into the second store.

Please be aware that the second store won't be filled if zero records go into the first store, and choose your stores appropriately.

If any of your stores can be the only empty store, perhaps you will have to get the rawdata via Ext.data.Request and load it into all stores afterwards.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.