我正在尝试在dataview中呈现一个表。一切都很好,但tpl渲染了两次:
第一:与数据一起加载的tpl内容第二:在没有任何数据的情况下单独呈现tpl
我发现这个问题已经被问到了另一个版本。但没有相关的答案来解决这个问题。ExtJS tpl渲染两次
{
xtype: 'dataview',
scrollable: true,
itemSelector: 'tr',
data: [{
selCodeType: 'selCodeType',
codeTypeMnc: 'codeTypeMnc'
}, {
selCodeType: 'selCodeType',
codeTypeMnc: 'codeTypeMnc'
}],
tpl: ['<table><thead>',
'<th>Select Code Type</th>',
'<th>Code Type MNC</th>',
'</thead>',
'<tbody>',
'<tpl for=".">',
'<tr>',
'<td>selCodeType</td>',
'<td>codeTypeMnc</td>',
'</tr>',
'</tpl>',
'</tbody></table>']
}
上述代码的结果
我也试过itemTpl。但运气不好。如果有人指出我在这里做错了什么,那会很有帮助。
感谢
必须使用store
而不是data
和dataview
s:
{
xtype: 'dataview',
scrollable: true,
itemSelector: 'tr',
store: {
data:[{
selCodeType: 'selCodeType',
codeTypeMnc: 'codeTypeMnc'
}, {
selCodeType: 'selCodeType',
codeTypeMnc: 'codeTypeMnc'
}]},
tpl: ['<table><thead>', '<th>Select Code Type</th>', '<th>Code Type MNC</th>', '</thead>', '<tbody>', '<tpl for=".">', '<tr>', '<td>selCodeType</td>', '<td>codeTypeMnc</td>', '</tr>', '</tpl>', '</tbody></table>']
}
工作示例:https://fiddle.sencha.com/#fiddle/18th