簡體   English   中英

在ExtJS中加載hasMany數據

[英]Loading hasMany data in ExtJS

我正在嘗試在ExtJS4中的hasMany關系中加載'嵌套'數據。 我的模型看起來像這樣:

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返回這個:

{
    "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()或類似的東西時。 它說不存在這樣的方法。 我認為在映射模型中的數據時會出現問題。

非常感謝任何幫助!

終於找到了問題。 供將來參考:

如果您在ExtJS的新MVC結構中使用包,請在關聯中定義鏈接類的完整路徑,如下所示:

hasMany: {model: 'Entrypage.model.EntrypageCriterium', name: 'brands', associationKey:'brands'}

您需要在hasMany關聯中設置associationKey屬性,因此它知道要使用哪個json屬性。

hasMany: {model: 'EntrypageCriterium',name:'brands', associationKey:'brands'}

請參閱此處的“加載嵌套數據”部分:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Reader

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM