2017-04-26 55 views
1

當我擴展例如Ext.button.Button組件時,我知道如何將參數傳遞給模板。我這樣做:如何設置DataView模板參數

renderTpl: '...{custom_parameter}...', 
getTemplateArgs: function() { 
    return { 
     custom_parameter: "Some value" 
    } 
} 

它的效果很好。但是現在我想在延伸Ext.DataView時也這樣做。讓我們假設我有一個像這樣定義一些模板:

Ext.define('Ext.ux.CustomComponent', { 
    extend: 'Ext.DataView', 
    ... 
    tpl: [ 
     '<div>{custom_parameter}</div>', 
     '<tpl for=".">', 
      ... 
     '</tpl>' 
    ] 
    ... 

我看到DataView缺少這個漂亮getTemplateArgs。那麼實現這個的另一種方法是什麼?

回答

1

一種選擇是在initConfig/constructor中初始化模板,以便將數據視圖的配置選項傳遞給模板。

templateArgs: { 
    custom_parameter: "Some value" 
},  
initConfig: function() { 
    this.tpl = new Ext.XTemplate(
     '<div>{[this.templateArgs.custom_parameter]}</div>', 
     '<tpl for=".">', 
       ... 
     '</tpl>', 
     { 
      templateArgs: this.templateArgs 
     } 
    ); 
} 
+0

是啊!我設法通過構造函數來實現這一點。謝謝! – Jacobian