比较ExtJS中的tpl值

时间:2018-06-26 07:21:40

标签: javascript extjs extjs4.1 extjs4.2

所以我有这个数据

data = [{
    "D": 1,
    "VALID": "N",
    "NUMBER": "7064089-14-1607"
}, {
    "D": 3,
    "VALID": "N",
    "NUMBER": "7064089-24-1106"
}, {
    "D": 5,
    "VALID": "N",
    "NUMBER": "7066097-14-1508"
}]

哪个会传递给extjs中的商店

fields: [{name: 'NUMBER', type: 'string'},{name: 'VALID', type: 'string'},{name: 'D', type: 'string'}]

这是我在 ExtJS 中的tpl代码:

tpl: [
'<div class="row">',
    '<div class="column" style="width: 125px">',
        '<h4>NUMBER </h4>',
        '<tpl for =".">',
        '<p>{NUMBER}</p>',
        '</tpl>',
    '</div>',
    '<div class="column" style = "width: 100px">',
        '<h4>VALID </h4>',
        '<tpl for =".">',
        '<p>{VALID}</p>',
        '</tpl>',
    '</div>',
    '<div class="column">',
        '<th></th>',
        '<tpl for =".">',
        '<p>{D}</p>',
        '</tpl>',
    '</div>',
'</div>'
]

如果在D上迭代的值大于1,有什么办法可以将tpl放入标签的tpl中?

例如要传输到ExtJS tpl的代码:

for i in D:
  if i >1:
    '<td class="gray">i</td>'
  else:
    '<td class="red">i</td>'

1 个答案:

答案 0 :(得分:0)

当然可以,如果这样的话

var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Kids: ',
'<tpl for="kids">',
    '<tpl if="age &gt; 1">',
        '<p>{name}</p>',
        '<p>Dad: {parent.name}</p>',
    '</tpl>',
'</tpl></p>'
);