加载在ExtJS中有很多数据 [英] Loading hasMany data in ExtJS

查看:82
本文介绍了加载在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']
});

我加载我的数据如下:

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结构中使用包,请定义关联中的链接类的完整路径: p>

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中有很多数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆