裏面的函數這應該解決您的問題:
'<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