zoukankan      html  css  js  c++  java
  • 把城市按首字母分类

    函数

    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-id="'+cityID+'">'+hotCity+'</a>');
    }
    var cityName=this.SIMPLIFIED_NAME;
    $(".city_"+key).append('<a href="javascript:void(0);" data-id="'+cityID+'">'+cityName+'</a>');
    })
    }
    //FIRST_LETTER
    //SIMPLIFIED_NAME CITY_ID
    //取得门店
    for(var i=0;i<stores.length;i++){
    var storeName = stores[i].NAME;
    var storeID = stores[i].CITY_ID;
    storesAdds.push(storeName);
    //console.log(storeName);
    };
    //取得城市下面的门店
    $(".city_item").find("a").on("click",function(event){
    event.stopPropagation();
    var cityID = parseInt($(this).attr("data-id"));
    $(".city_item_adds").show();
    $(".city_item_adds").find("ul").empty();
    $(".tab_box").hide();
    $(".city_item").hide();
    var flag=0;
    for(var i=0;i<stores.length;i++){
    var storeID = stores[i].CITY_ID;

    if(storeID == cityID){
    flag++;
    var storeName = stores[i].NAME;
    var store_ID = stores[i].STORE_ID;
    $(".city_item_adds").find("ul").append('<li id="'+store_ID+'">'+storeName+'</li>');
    }
    }
    if(flag==0){
    $(".city_item_adds").find("ul").empty().append('暂时还没有门店');
    }
    });

    }});

  • 相关阅读:
    ExtJs系列教程
    linux 服务器时间 timedatectl命令时间时区操作详解
    aws CloudWatch Events
    AWS Shield
    aws ssm指令
    failed to set bridge addr: "cni0" already has an IP address different from 10.244.0.1/24
    AWS Systems Manager
    Amazon Inspector
    AWS 安全培训
    Amazon Inspector
  • 原文地址:https://www.cnblogs.com/smght/p/5163185.html
Copyright © 2011-2022 走看看