2012-10-11 70 views
0

Extjs4 Store類的data屬性描述了一個對象層次結構。我把它作爲我店的數據屬性,因爲數據是靜態的;不需要額外撥打服務器來填充商店。我以前做過這個,但是這次我的許多關係沒有被填充。我嘗試了多種方法來解決這個問題,但我很難過。你會看看它,看看我錯過了什麼嗎?Extjs4 hasMany()關係無法從商店的「數據」屬性中加載

對象的關係是:MarineForm has MarineFormSections which has MarineFormFields

它店裏的數據屬性

Ext.define('MAP.store.MarineFormStore', { 
    extend: 'Ext.data.Store', 
    model: 'MAP.model.MarineForm', 
    data:[ 
     { 
      species:'Mackerel', 
      gear:null, 
      sections:[ 
       { 
        name:'General Info', 
        formFields:[ 
         { 
          xtype:'textfield', 
          name:'firstField', 
          allowBlank:false, 
          fieldLabel:'First Field' 
         } 
        ] 
       } 
      ] 
     } 
    ] 

}); 

根模型

Ext.define('MAP.model.MarineForm', { 
    extend: 'Ext.data.Model', 

    fields: [ 
     {name: 'species', type: 'string'}, 
     {name: 'gear', type: 'string'} 
    ], 

    hasMany: { 
     model: 'MAP.model.MarineFormSection', 
     name: 'sections' 
    } 

}); 

的的hasMany類

Ext.define('MAP.model.MarineFormSection', { 
    extend: 'Ext.data.Model', 

    fields: [ 
     'id', 
     {name: 'name', type: 'string'} 
    ], 

    hasMany: { 
     model: 'MAP.model.MarineFormField', 
     name: 'formFields' 
    } 

}); 

所述的hasMany的的hasMany類(第三層嵌套)

Ext.define('MAP.model.MarineFormField', { 
    extend: 'Ext.data.Model', 

    fields: [ 
     'name', 
     {name:'allowBlank', type:'boolean'}, 
     'fieldLabel', 
     'xtype', 
     //next ones are for comboboxes. Not used all the time. -jg 
     'store', 
     'valueField', 
     'displayField' 
    ] 
}); 

下面是從內鉻查詢存儲的輸出:

rootStore = Ext.getStore('MarineFormStore') // -> the store 
sections = rootStore.getAt(0).sections() // -> hasMany store 
sections.getCount() // -> 0 

我試着:

  1. Removi納克MarineFormField hasManyMarineFormFields
  2. 在根存儲的data字段中添加一個ID,MarineFormField
  3. 三重檢查任何錯別字

感謝您抽出寶貴的時間!

回答

0

這在我看來,所有你缺少的是這在你的存儲配置(或不太可能你只是忘了裝載存儲):

proxy: { 
    type: 'memory', 
    reader: { 
     type: 'json', 
    } 
},  

This JsFiddle幾乎是你的代碼包含這種變化,它似乎工作得很好。

+0

就是這樣!謝謝你救了我一些痛苦和悲傷。 –