我有一个方法,方法如下:
createTip : function() {
var eventTip = new Ext.XTemplate(
'<tpl if="EventType == \'ONE\'">',
'<p> This is event one </p>',
'</tpl>',
'<tpl if="EventType == \'Two\'">',
return null;
'</tpl>'
);
return eventTip;
}我想做的是,如果EventType是'TWO',让方法返回null。这个是可能的吗?
就像上面的代码一样。我知道这是不可能的,但无论如何都有可能这样做。很大程度上,如果EventType是2,我不希望创建xtemplate。
谢谢
发布于 2012-06-30 00:41:34
applyDataToMyTemplate: function(data){
if (data.EventType === 'Two'){
return null; //or '', or false, or whatever you need
} else {
return this.createTip().apply(data); //or some such hackery
}
}发布于 2013-01-05 06:16:49
看起来如果你真的需要返回null,你可能需要的不是XTemplate。我不知道有任何使用模板这样做的用例,如果xtemplate返回的不是它应该返回的html片段,它应该会破坏大多数小部件。如果您只是需要在EventType为2时不显示任何内容,那么您可以使用模板函数来调整生成的HTML,或者通过构建一个字符串来做几乎任何其他您想做的事情。这样做会放弃提前创建部分dom元素以供重用的好处,尽管XTemplate应该提供这些好处:
new Ext.XTemplate(
'{[this.buildTemplate(values)]}',
{
buildTemplate: function (values) {
if (values.EventType === "One") {
return "<p> This is event one </p>";
} else {
return '';
}
}
}
)https://stackoverflow.com/questions/11225435
复制相似问题