这是我的 Sencha Touch 2 代码,它显示了 Ext.data.List 组件中的 JSON 列表数据。我使用 tpl 来创建列出的项目。现在我需要将此列表转换为嵌套列表。但是失败了,我不知道如何将列表视图的 itemTpl 移动到嵌套列表的 getItemTextTpl?
带列表的代码
Ext.define('Mobile.view.ActionListView', {
extend: 'Ext.dataview.List',
xtype: 'actionsummary',
id: 'actionsummaryList',
config: {
title: 'Actions',
store: 'ActionSummaryStore',
//data:[{"Id":1,"TransactionType":"Transaction 1","ActionList":[{"Id":1,"Count":4,"Action":"Action Item 1","CurrentStatus":"Open"},{"Id":2,"Count":14,"Action":"Action Item 3","CurrentStatus":"Open"},{"Id":3,"Count":44,"Action":"Action Item 5","CurrentStatus":"Close"}]}],
emptyText: 'Loading action items...',
itemTpl: Ext.create('Ext.XTemplate', '<tpl for=".">',
'<div class="action-item-container"><p class="action-text">{TransactionType}</p>',
'<tpl for="ActionList"><tpl for=".">',
'<div><ul>',
'<li><a href="javascript:void(0)"><span class="action-count">{CurrentStatus}<tt>({Count})</tt></span><span class="btn-{Action}">{Action}</span></a></li>',
'</ul></div>',
'</tpl></tpl>',
'</div>',
'</tpl>'
)
}
});
带有嵌套列表的新代码
Ext.define('Mobile.view.ActionListView', {
extend: 'Ext.dataview.NestedList',
xtype: 'actionsummary',
id: 'actionsummaryList',
config: {
title: 'Actions',
store: 'ActionSummaryStore',
useTitleAsBackText: false,
onItemDisclosure: true,
//data:[{"Id":1,"TransactionType":"Transaction 1","ActionList":[{"Id":1,"Count":4,"Action":"Action Item 1","CurrentStatus":"Open"},{"Id":2,"Count":14,"Action":"Action Item 3","CurrentStatus":"Open"},{"Id":3,"Count":44,"Action":"Action Item 5","CurrentStatus":"Close"}]}],
itemTpl: Ext.create('Ext.XTemplate', '<tpl for=".">',
'<div class="action-item-container"><p class="action-text">{TransactionType}</p>',
'<tpl for="ActionList"><tpl for=".">',
'<div><ul>',
'<li><a href="javascript:void(0)"><span class="action-count">{CurrentStatus}<tt>({Count})</tt></span><span class="btn-{Action}">{Action}</span></a></li>',
'</ul></div>',
'</tpl></tpl>',
'</div>',
'</tpl>'
)
},
getTitleTextTpl: function () {
return 'Summary View';
},
getItemTextTpl: function (node) {
// return '<div><strong>{name}:</strong> <em>{description}</em></div>';
//replace this code with my above itemTPL
}
});