admin管理员组文章数量:1389762
The documentation about List mention that itemTpl follows the XTemplate syntax.
I would like to use member functions in my itemTpl
If I initialize itemTpl with an XTemplate and that the member function has no argument it works:
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate('<i>{name} {[this.hello()]}</i>', {
hello: function () {
return 'Hello';
}
})
But as soon as I try to pass an argument (like in the two examples below) it does not work anymore:
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' is not a function (evaluating 'fm.helloWorld(values['name'])')
I guess I should not create a new Ext.XTemplate object. Is there any solution to pass the member functions without creating a separate XTemplate?
Or should I give up on the List and build the list myself in the template?
The documentation about List mention that itemTpl follows the XTemplate syntax.
I would like to use member functions in my itemTpl
If I initialize itemTpl with an XTemplate and that the member function has no argument it works:
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate('<i>{name} {[this.hello()]}</i>', {
hello: function () {
return 'Hello';
}
})
But as soon as I try to pass an argument (like in the two examples below) it does not work anymore:
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' is not a function (evaluating 'fm.helloWorld(values['name'])')
I guess I should not create a new Ext.XTemplate object. Is there any solution to pass the member functions without creating a separate XTemplate?
Or should I give up on the List and build the list myself in the template?
Share Improve this question asked Sep 28, 2011 at 18:16 Christian LemerChristian Lemer 8939 silver badges15 bronze badges3 Answers
Reset to default 6The following code should work:
items: {
xtype: 'list',
store: myStore,
itemTpl: new Ext.XTemplate(
'<i>{name} {[this.helloWorld(values.name)]}</i>',
{
piled: true,
helloWorld: function (name) {
return 'Hello ' + name;
}
})
}
your first example would work, with values.name
instead of just name
Use {[this.helloWorld(name)}
instead of {[this.helloWorld(values.name)}
This usage is also ok:
itemTpl :new Ext.XTemplate( '<section class="movieListItem">',
'<img src="{UserLogo:this.showLogo}"/>',
'<h1>{NickName}</h1>',
'<div>{Content}</div>',
'</section>',
{
showLogo:function(value){
}
});
本文标签: javascriptUsing member functions within Sench Touch List itemTplStack Overflow
版权声明:本文标题:javascript - Using member functions within Sench Touch List itemTpl - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744720787a2621681.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论