我有这个问题,我需要知道是否可以对XTemplate内的参数进行字符串比较操作。我需要知道字符串中是否有子字符串。 这是我的代码。我需要一份声明,检查是否" L"是RIV_Filtro
var detailRivenditoreTemplate = new Ext.XTemplate(
'<tpl for="rivenditori">',
'<div id="boxDettaglioRivenditori">',
'<h1>{RIV_RagioneSociale}</h1>',
'<div>',
'{RIV_Indirizzo}',
'<p>{RIV_CAP} - {RIV_Localita}, {RIV_Regione}</p>',
'{RIV_Paese}',
'</div>',
'</div>',
'</tpl>'
);
我想这是不可能的,但我只是问一个人是否已经面临这个问题。 提前谢谢
答案 0 :(得分:1)
您可以使用以下模板函数:
var detailRivenditoreTemplate = new Ext.XTemplate(
'<tpl for="rivenditori">',
'<div id="boxDettaglioRivenditori">',
'<h1>{RIV_RagioneSociale}</h1>',
'<div>',
'<tpl if="[this.checkFilter(RIV_Filtro)] > -1">{RIV_Indirizzo}</tpl>',
'<p>{RIV_CAP} - {RIV_Localita}, {RIV_Regione}</p>',
'{RIV_Paese}',
'</div>',
'</div>',
'</tpl>', {
checkFilter: function(filter) {
return filter.indexOf("L");
}
}
);
这是一个小提琴:http://jsfiddle.net/johanhaest/KJfDE/
在示例中,仅当RIV_Filtro包含“L”时,才会显示RIV_Indirizzo。