在我心目中的理想世界中,我会在Ext.dataview.List
:
itemTpl: '{name:customFunction}'
其中customFunction是全局/静态函数我可以在所有模板上重用。什么是最接近现实世界的解决方案?
答案 0 :(得分:3)
最接近的就像你说的那样......只需将自定义功能添加到Ext.util.Format
。
示例:
Ext.define(null, {
override: 'Ext.util.Format'
,customFunction: function(value, append) {
return 'This is it: '
+ value
+ (Ext.isDefined(append) ? append : ''); // you can use args too
}
});
答案 1 :(得分:0)
这可能是你最好的选择:
itemTpl: new Ext.XTemplate(
'{[this.getGlobalValue()]}',
{
getGlobalValue: MyApp.util.Utils.globalTplFunction
}
)
然后,在您的Utils文件中:
Ext.define('MyApp.util.Utils', {
singleton: true,
globalTplFunction: function() {
//do whatever here
return "Result!";
}
});