我需要一个属性作为模型中的集合,所以我尝试了关联,但当我查看存储加载事件( store -> Record ->Data ->Array Property)中的“Record”参数时,我得到的结果类似于"object Object",而不是数组集合。
当我查看记录中的"raw“属性时,我得到了正确的数组集合。
I.e
我的代码
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响应将是:
{"res":[{"examId":1,"examName":"mathematics","examTypes":[{"examTypeId":1,"examId":"1","examType":"MCQ","active":true}]}],"totalCount":1,"success":true}在我存储加载事件中,当我查看"records“参数时,
records[1].data.examTypes="[object Object]"
as like object , but iam getting in raw property
records[1].raw.examTypes = proper array collection.我不知道我错在哪里,也不知道是否有任何财产丢失/分配错误。
发布于 2011-12-27 18:14:14
尝试在字段定义中使用{ name: 'examTypes', type: 'auto' }。它不会将examTypes转换为record,但它使数组保持不变。
https://stackoverflow.com/questions/8638543
复制相似问题