里面的函数这应该解决您的问题:
'<tpl switch="post_type">',
'<tpl case="new_user">',
'<p>{post_text_teaser}</p>',
'<p>{timestamp}</p>',
'<tpl default>',
'<p>{[Ext.String.ellipsis(values.post_text_teaser,4,false)]}</p>',
'</tpl>'
你可以找到更多关于XTemplate的信息在Sencha Docs
模板成员函数的事情是,据我所知,你不能直接在itemTpl中定义它们,但需要明确定义一个新的XTemplate,然后在你的itemTpl中使用它。见例如:
var tpl = new XTemplate(
'<tpl switch="post_type">',
'<tpl case="new_user">',
'<p>{post_text_teaser}</p>',
'<p>{timestamp}</p>',
'<tpl default>',
'<p>{[this.shorten(values.post_text_teaser)]}</p>',
'</tpl>',
{
shorten: function(name){
return Ext.String.ellipsis(name,4,false);
}
}
);
...
itemTpl: tpl,
...
Senchafiddle example
将在下面的代码这应该工作正常(刚从XTemplate插入上面的代码)。
itemTpl: new XTemplate(...),
Senchafiddle example
希望这sortens吧!
编辑注意到我哈得错过了结束标记,有时它的工作原理没有他们,但它是很好的做法,始终使用它们,因为它们可能会导致有趣的错误(在这种情况下,缺少对所生成的代码支架)。
@johan和@sra记录OP中的编辑 - 'itemTpl'末尾有'.join('')' - 当包含函数时会出现问题吗? – pepe
只要你运行模板为XTemplate这应该是没有问题的 – sra