vineth
vineth

Reputation: 883

In EXTJS-4 I am not getting associations data as Array Collection in Store(load event) Record ->Data-> Property)

I need one property as collection in a model, so i tried associations but when i look on "records" parameter in store load event, (Store-> Record ->Data ->Array Property) i am getting like "[object Object]", but not as array collection.

when i watch "raw" property in Record, i am getting proper array collection .

I.e

My Code

Ext.define('MyApp.model.user.examModl', {
    extend: 'Ext.data.Model',    
    idProperty :'examId',
    hasMany: 'MyApp.model.user.examTypeModl',    
            proxy:{          
        type: 'ajax',      
         api: {
                read: 'readExam.htm'          //url   to read data from db
            },
        reader: {
            type: 'json',
            root: 'res',
             idProperty: 'examId',
            successProperty: 'success',
            totalProperty: 'totalCount'
        },
        writer: {
                type: 'json',  
                 encode: true,
                root: 'res',
                writeAllFields : true
            }
    },
     fields:[{
                    name: 'examId',
                    type: 'string'
                },
                {
                    name: 'examName',
                    type: 'string'
                },
            {
                    name: 'examTypes',//It shoud be in array
                    type: 'string'            // is there any collection type to be specified ?
                }] ,
                associations: [
        {type: 'hasMany', model: 'MyApp.model.user.examTypeModl', name: 'examTypes'}
    ]
});

Ext.define('MyApp.model.user.examTypeModl', {
    extend: 'Ext.data.Model',    
    idProperty :'examTypeId',
    belongsTo: 'examTypes',  
     fields:[{
                    name: 'examTypeId',
                    type: 'string'
                },
                {
                    name: 'examId',
                    type: 'string'
                },              
                {
                    name: 'examType',
                    type: 'string'
                },

                { name: 'active',
                    type: 'bool'

                }]    
});

My json responce will be :-

{"res":[{"examId":1,"examName":"mathematics","examTypes":[{"examTypeId":1,"examId":"1","examType":"MCQ","active":true}]}],"totalCount":1,"success":true}

In my store load event, when i watch "records" parameter,

 records[1].data.examTypes="[object Object]"

as like object , but iam getting in raw property

 records[1].raw.examTypes  = proper array collection.

i don't know where i am going wrong or any property missing/wrongly assigned.

Upvotes: 1

Views: 3723

Answers (1)

Krzysztof
Krzysztof

Reputation: 16150

Try to use { name: 'examTypes', type: 'auto' } in your fields definition. It doesn't convert examTypes to record, but it keeps array untouched.

Upvotes: 1

Related Questions