【问题标题】:Comparing tpl value in ExtJS比较 ExtJS 中的 tpl 值
【发布时间】:2018-06-26 07:21:39
【问题描述】:

所以我有这个数据

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 中传递给 store

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 for tag 中放置一个 tpl?

例如要转移到ExtJStpl的代码:

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

【问题讨论】:

  • 你能进一步解释你的意思吗? “在标签内放一个”是什么意思?

标签: javascript extjs extjs4.1 extjs4.2


【解决方案1】:

当然,你可以这样做,如果这样的话,你可以使用

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>'
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    相关资源
    最近更新 更多