使用Sench Touch List itemTpl中的成员函数
Using member functions within Sench Touch List itemTpl
关于List的文档提到itemTpl遵循XTemplate语法。
我想在我的itemTpl中使用成员函数
如果我用XTemplate初始化itemTpl,并且成员函数没有参数,它可以工作:
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate('<i>{name} {[this.hello()]}</i>', {
hello: function () {
return 'Hello';
}
})
但是一旦我试图传递一个参数(就像下面的两个例子),它就不再工作了:
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate('<i>{name} {[this.helloWorld(name)}</i>', {
helloWorld: function (name) {
return 'Hello ' + name;
}
})
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate('<i>{name} {name:helloWorld}</i>', {
helloWorld: function (string) {
return 'Hello ' + name;
}
})
TypeError: 'undefined'不是一个函数(求值'fm.helloWorld(values['name'])')
我想我不应该创建一个新的Ext.XTemplate对象。是否有任何解决方案来传递成员函数而不创建单独的XTemplate?
或者我应该放弃List并在模板中自己构建列表?
下面的代码应该可以工作:
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate(
'<i>{name} {[this.helloWorld(values.name)]}</i>',
{
compiled: true,
helloWorld: function (name) {
return 'Hello ' + name;
}
})
}
您的第一个示例将工作,values.name
而不仅仅是name
使用{[this.helloWorld(name)}
代替{[this.helloWorld(values.name)}
这种用法也是可以的:
itemTpl :new Ext.XTemplate( '<section class="movieListItem">',
'<img src="{UserLogo:this.showLogo}"/>',
'<h1>{NickName}</h1>',
'<div>{Content}</div>',
'</section>',
{
showLogo:function(value){
}
});
相关文章:
- 成员函数中的Javascript“this”object==“window”
- CakePHP错误:在非对象上调用成员函数get(),使用cakejavascript助手时出错
- 对象属性不是在工厂成员函数内部创建的
- 在setTimeout中执行jQuery成员函数而不关闭的方法
- 如何从父类中记录成员函数
- Javascript中的成员函数
- 为什么要在构造函数中定义事件处理程序成员函数(内联)以便使用“unbind”
- 在 Jquery 插件中调用成员函数
- 成员函数的 JS 最佳实践
- 如何在javascript中声明成员函数?获取“TypeError: Object.function is not a
- 如何使用字符串引用闭包,就像我在不使用 eval 的情况下使用成员函数一样
- 如何在javascript中调用类成员函数
- 调用数字文字的成员函数
- 用成员函数扩展React.js存储数据结构
- 如何使“this”引用成员函数而不是其所有者类的实例
- 将对象的成员函数公开为全局函数
- 在coffeescript类中是否可以有一个同名的静态函数和成员函数
- 对象成员函数的回调?(Javascript)
- 在dojo模块中引用父级的JSON/javascript成员函数
- Javascript对象和传递的成员函数作为参数