我有以下代码
Ext.regModel('Centre', {
fields: ['name', 'url']
});
Ext.application({
name: 'Sencha',
launch: function() {
var panel = new Ext.Panel({
fullscreen: true,
dockedItems: [
{
xtype: "toolbar",
dock: "top",
title: "DEMO APP"
},
{
xtype: "toolbar",
items: [
{
iconMask: true,
iconCls: "download"
},
{
iconMask: true,
iconCls: "favorites"
},
{
iconMask: true,
iconCls: "search"
},
{
iconMask: true,
iconCls: "user"
}
]
},
{
xtype: 'list',
itemTpl: '{name}',
sorters: 'name',
store: {
fields: ['name', 'url'],
data: centers
},
itemConfig: {
tpl: '{url}'
},
listeners: {
itemtap:function(data,index){
var record = data.getStore().getAt(index);
redirect_url = record.raw.url
// the record that has been clicked.
window.location = redirect_url
}
}
},
]
});
}
});
centers
有一个中心列表。我想对列表进行排序和分组。试过getGroupString()但没有帮助。可能是我错过了什么..
答案 0 :(得分:3)
您的列表需要具有配置属性grouped:true
(// indexBar:true as well if you want the alphabet on the side)
您的商店需要实施getGroupString
功能
getGroupString: function(record) { return record.get('name') }
答案 1 :(得分:2)
对于使用2.1+的任何人,现在的语法是在配置中使用groupFn函数定义一个组对象:
grouper: {
groupFn: function(record) {
return record.get('name').substr(0, 1);
},
sortProperty: 'name'
}