2

我有以下代码

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() 但没有帮助。可能是我错过了什么..

4

2 回答 2

3

您的列表需要具有 config 属性grouped:true

(// indexBar:true as well if you want the alphabet on the side)

您的商店需要getGroupString实现该功能

getGroupString: function(record) { return record.get('name') }
于 2011-11-08T19:54:21.037 回答
2

对于使用 2.1+ 的任何人,现在的语法是在配置中使用 groupFn 函数定义一个组对象:

grouper: {
    groupFn: function(record) {
        return record.get('name').substr(0, 1);
    },
    sortProperty: 'name'
}
于 2013-07-28T22:30:09.727 回答