分组和排序列表在sencha触摸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(),但没有帮助。也许我错过了什么…

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

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

你的商店需要有getGroupString功能实现

getGroupString: function(record) { return record.get('name') }

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

grouper: {
    groupFn: function(record) {
        return record.get('name').substr(0, 1);
    },
    sortProperty: 'name'
}

最新更新