这应该可以解决您的问题:
'<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>'
你可以在Sencha Docs找到更多关于 XTemplate 的信息
模板成员函数的问题是,据我所知,您不能以常规方式直接在 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 示例
这应该和下面的代码一样正常工作(只需插入上面 XTemplate 中的代码)。
itemTpl: new XTemplate(...),
Senchafiddle 示例
希望这能解决问题!
编辑注意到我错过了结束标签,有时没有它们也可以工作,但最好总是使用它们,因为它们可能会导致有趣的错误(在这种情况下,生成的代码中缺少括号)。