把城市按首字母分类
函数
function group_pinyin(list,group_flag){
var array=[];
$.each(list,function(){
var store=[];
var group = this.FIRST_LETTER;//首字母
var item = this;
var array_index=-1;
var id = this[group_flag];
$.each(array,function(i){
if(this[group]){
store = this[group];
array_index = i;
return false;
}
})
var add = true;
$.each(store,function(){
if(this[group_flag]==id){
add=false;
}
})
if(add)store.push(item);
var obj = {sort:group};
obj[group]=store;
if(array_index!=-1){
array[array_index]=obj;
}else{
array.push(obj);
}
})
return array;
}
引用
ajax({data:data,success:function(json){
var citys = toJSON(json.citys);
//console.log(citys);
citys = group_pinyin(citys,"PROVINCE_ID");
var stores = toJSON(json.stores);
var list = toJSON(json.list);
//citys = citys[0].FIRST_LETTER;
//console.log(stores);
//取得城市
for(var i=0;i<citys.length;i++){
var key = citys[i].sort;
var list = citys[i][key];
$.each(list,function(){
var hotId = this.IS_HOT;
var cityID = this.CITY_ID;
if(hotId == 12781001){
var hotCity = this.SIMPLIFIED_NAME;
$("#city_item_1").append('<a href="javascript:void(0);" data-).empty().append('暂时还没有门店');
}
});
}});