列表按编号排序sencha

时间:2011-11-22 15:06:52

标签: sencha-touch

我正在使用sencha touch,并且在排序时按编号排序Ext.list时遇到问题。

更具体一点:

代码:

mydata=[

    {id:'1', name:"Toni Vespa " , address:"Iban Gavirol, TLV  ",long:"33.20",lati:"31.20",distance:"1"},
    {id:"2", name:"Toni Vespa " , address:"Roteshild, TLV  ",long:"34.79",lati:"32.06",distance:"23"},
    {id:"3", name:"Toni Vespa " , address:"Dizingoff, TLV  ",long:"34.80",lati:"32.07",distance:"44"},
    {id:"4", name:"Toni Vespa " , address:"Hanamal, TLV  ",long:"30.10",lati:"30.01",distance:"55"},
    {id:"5", name:"Toni Vespa " , address:"Shenkar, Herzelia  ",long:"33.20",lati:"29.20",distance:"66"},
    {id:"6", name:"Toni Vespa " , address:"Oshiskin, Ramat Hasharon  ",long:"30.20",lati:"29.20",distance:"4"},
    {id:"7", name:"Toni Vespa " , address:"Waizman, Kfar Sava  ",long:"33.20",lati:"31.20",distance:"44"},
    {id:"8", name:"Toni Vespa " , address:"Hatayasim, Ramat Gan  ",long:"33.20",lati:"31.20",distance:"3"},
    {id:"9", name:"Toni Vespa " , address:"Herzel, Be'er Sheva  ",long:"33.20",lati:"31.20",distance:"54"},
    {id:"10", name:"Toni Vespa " , address:"Hashunit, Eilat  ",long:"33.20",lati:"31.20",distance:"53"}
    ];

Ext.regModel('Stores', {
    fields: [{name:'id',type:'string'} , {name:'name',type:'string'} , {name:'address',type:'string'} ,{name:'long',type:'number'} , {name:'lati',type:'number'},{name:'distance',type:'number'}]
});


 var ListStore= new Ext.data.Store({
    model:'Stores',
    /*sorters: 'distance',
    getGroupString : function(record) {
        return record.get('distance');
    },*/    

});

我正在尝试按距离对距离记录进行排序。

我会很高兴得到任何帮助。 谢谢,

2 个答案:

答案 0 :(得分:0)

我认为可能是因为您将距离设置为字符串,请尝试将其设置为整数(删除周围的引号)

答案 1 :(得分:0)

我的解决方案:

我添加了

var ListStore = new Ext.data.Store({     型号:“商店”,     分拣机:'距离',     getGroupString:function(record){         return record.get('distance');     },

}); 提示:如果要在更新列表后对列表进行排序,请尝试: ListStore.sort('recored name','ASC');