2014-01-31 33 views
0

我有兩個門店和其相應的模型......顯示不同商店的單一xtemplte數據

輪詢模式

Ext.define('PollsTest.model.Poll', { 
extend: 'Ext.data.Model', 
xtype : 'poll', 

requires: [ 
    'Ext.data.identifier.Uuid' 
], 


config: { 
    fields: [ 
     { name: 'title'}, 
     { name: 'uri' }, 


    ], 
    identifier: { 
       type: 'uuid' 
      }, 
    hasMany : 
      [ 
       { 
        model : 'PollsTest.model.Choice', 
        name : 'Choices', 
        primaryKey : 'title', 
        foreignKey : 'title', 
        foreignStore : 'Choices' 
       } 
      ] 

} 


}); 

選擇模型

Ext.define('PollsTest.model.Choice', { 
    extend: 'Ext.data.Model', 

    requires: [ 
     'Ext.data.identifier.Uuid' 
    ], 


    config: { 
     fields: [ 
      { name: 'choice', type: 'auto' }, 
      { name: 'votes', type: 'auto' }, 
      {name : 'title', type: 'auto'}, 
      {name : 'uri', type : 'auto'} 

     ], 

     identifier: { 
        type: 'uuid' 
       }, 

    belongsTo : { 
         model : 'PollsTest.model.Poll', 
         name : 'Choices', 
         primaryKey : 'title', 
         foreignKey : 'title', 
         foreignStore : 'Choices', 
         getterName: 'getChoice', 
         setterName: 'setChoice' 

       }   
    } 



    }); 

和我必須在我的模板中以這樣的方式顯示:

'<p>{title} <br> choices : {uri}<br></p>', 
'<tpl for "choices">',      
'<p> {Choice.choice} <br></p>', 
'</tpl>', 

現在我沒有收到任何錯誤,但選擇不顯示在模板中。 模板是不在列表中的面板。

任何想法可以理解

回答

0

你必須通過操縱兩個店,然後可以用來渲染模板數據對象以創建單個對象。我不確定是否有其他方式來做到這一點。

+0

我如何通過操縱兩個商店創建單個對象?你能否提供任何工作示例/代碼? – Jithu

+0

假設我有2個商店說**民意調查**和**選擇**?我怎樣才能做到這一點?? – Jithu

0

我建議使用DataView,並學習如何使用XTemplates

這可以通過使用XTemplate自定義幫助函數完成,假設數據已經加入或不需要某種異步調用。

相關問題