sencha touch 的热门城市或定位显示问题

Geomen 发布于 2015/03/09 14:48
阅读 611
收藏 0

请教一下:

我的效果如图:


indexbar的“是可以正常显示”,但是列表里的定位一直显示在最后面,要怎样排序能让它排在前面呢?

控制器大概是这样的:从缓存里拿

var cityListStore = Ext.getStore('CityList');
        var localCityList = me.getLocalStorage('city_list');
        var gpsCity = me.getApplication().getController('Main').getGpsCity();
        gpsCity = Ext.decode(gpsCity);
        var gps = {cityid: 000000,city: gpsCity.city, pingyin: 'a', firstchar: '定位'};
        if(localCityList){ //先取本地缓存.
            cityListStore.setData(Ext.decode(localCityList));
            cityListStore.insert(0,gps);
            console.log(cityListStore);
            var cityListPage = Ext.ComponentManager.get('cityPage');
            if (!cityListPage) {
                cityListPage = Ext.Viewport.add({xtype: 'cityPage'});
            }
            Ext.Viewport.setMasked(false);
            cityListPage.show();
        }



视图里是这样的:

{
                xtype: 'list',
                id: 'city_list',
                scrollable: {
                    direction: 'vertical',
                    directionLock: true
                },
                store: 'CityList',
                indexBar: {
                    zIndex: 2,
                    //listPrefix: '#'
                    letters:[
                        '定位','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
                    ]
                },
                itemTpl: '{city}',
                grouped: true
            }



MODEL模型里是这样的:

Ext.define('WX.model.CityList',{
    extend: 'Ext.data.Model',
    config: {
        fields:[
            {name: 'cityid', type: 'int'},
            {name: 'city', type: 'string'},
            {name: 'pinyin', type: 'string'},
            {name: 'firstchar', type: 'string'}
        ]
    }
});



store里是这样的:

Ext.define('WX.store.CityList',{
    extend: "Ext.data.Store",
    config:{
        model: 'WX.model.CityList',
        autoLoad: true,
        autoDestroy: true,
        sorters: 'pinyin',
        grouper:{
            groupFn:function(record){
                return record.get('firstchar');
            }
        },
        header:{
            "Content-type": "application/json"
        }
    }
});



请帮忙一下,谢谢~~

加载中
0
Geomen
Geomen

@xiashulin 我的解决办法是:

显示城市列表的时候控制器执行:

var me = this;
        var cityListStore = Ext.getStore('CityList');
        var localCityList = me.getLocalStorage('city_list');
        var currentCity = me.getLocalStorage('gps_city');
        var gps = new Object({cityid: 0, city: '<b>定位:</b>'+currentCity, pingyin: '0', firstchar: '#'});
        cityListStore.setData(gps);
        if (localCityList) { //先取本地缓存.
            cityListStore.addData(JSON.parse(localCityList));
            var cityListPage = Ext.ComponentManager.get('cityPage');
            if (!cityListPage) {
                cityListPage = Ext.Viewport.add({xtype: 'cityPage'});
            }
            cityListPage.show();
        } else {
}



视图:

xtype: 'list',
                id: 'city_list',
                scrollable: {
                    direction: 'vertical',
                    directionLock: true
                },
                store: 'CityList',
                indexBar: {
                    zIndex: 2,
                    //listPrefix: '#'
                    letters:[
                        '#','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
                    ]
                },
                itemTpl: '{city}',
                grouped: true



效果图:

返回顶部
顶部