在 ExtJS 中加载 hasMany 数据 [英] Loading hasMany data in ExtJS
问题描述
我正在尝试在 ExtJS4 的 hasMany
关系中加载嵌套"数据.我的模型看起来像这样:
I'm trying to load 'nested' data in a hasMany
relation in ExtJS4.
My model looks like this:
Ext.define("Entrypage.model.Entrypage",{
extend: "Ext.data.Model",
fields: ['id','title','urlkey','text','picture','keywords', 'searchterms','description','critriamodus'],
hasMany: {model: 'EntrypageCriterium',name:'brands'},
proxy: {
type: 'ajax',
url: '/Admin/extjson/entrypages',
reader: {type:'json', root:'entrypages'}
}
});
和EntrypageCriterium
:
Ext.define("Entrypage.model.EntrypageCriterium",{
extend: "Ext.data.Model",
fields: ['id','type','title']
});
我像这样加载我的数据:
I load my data like so:
Entrypage.load("nikon-coolpix",{success:function(record,options,success){
console.log(record);
}});
加载良好.Json 返回这个:
It loads fine. Json returns this:
{
"success": true,
"entrypages":[{
"id":"1",
"urlkey":"nikon-coolpix",
"title":"Nikon Coolpix",
"text":"Some blahblah about Nikon",
"keywords":"nikon,coolpix,digitale,camera",
"description":"Nikon Coolpix camera's",
"picture":"Nikon Coolpix camera's",
"searchterms":"nikon coolpix",
"language":"nl",
"brands":[
{"id":27038,"title":"Nikon","type":"brand"}
]
}]
}
但是当我尝试 record.brands()
或类似的东西时.它说不存在这样的方法.我认为映射模型中的数据时出了点问题.
But when I try record.brands()
or anything like that. It says no such method exists.
I think something is going wrong in mapping the data in the model.
非常感谢任何帮助!
推荐答案
终于发现问题了.以供将来参考:
Finally found the problem. For any future reference:
如果您在 ExtJS 的新 MVC 结构中使用包,请在关联中定义链接类的完整路径,如下所示:
If you're using packages in the new MVC structure of ExtJS, define the full path to the linked class in your association like so:
hasMany: {model: 'Entrypage.model.EntrypageCriterium', name: 'brands', associationKey:'brands'}
这篇关于在 ExtJS 中加载 hasMany 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!