首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在EXTJS-4中,我没有在Store(load event) Record -> data -> Property中以数组集合的形式获取关联数据)

在EXTJS-4中,我没有在Store(load event) Record -> data -> Property中以数组集合的形式获取关联数据)
EN

Stack Overflow用户
提问于 2011-12-27 03:24:54
回答 1查看 3.7K关注 0票数 1

我需要一个属性作为模型中的集合,所以我尝试了关联,但当我查看存储加载事件( store -> Record ->Data ->Array Property)中的“Record”参数时,我得到的结果类似于"object Object",而不是数组集合。

当我查看记录中的"raw“属性时,我得到了正确的数组集合。

I.e

我的代码

代码语言:javascript
复制
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'

                }]    
});

我的json响应将是:

代码语言:javascript
复制
{"res":[{"examId":1,"examName":"mathematics","examTypes":[{"examTypeId":1,"examId":"1","examType":"MCQ","active":true}]}],"totalCount":1,"success":true}

在我存储加载事件中,当我查看"records“参数时,

代码语言:javascript
复制
 records[1].data.examTypes="[object Object]"

as like object , but iam getting in raw property

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

我不知道我错在哪里,也不知道是否有任何财产丢失/分配错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-27 18:14:14

尝试在字段定义中使用{ name: 'examTypes', type: 'auto' }。它不会将examTypes转换为record,但它使数组保持不变。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8638543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档