• 把城市按首字母分类


    函数

    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('暂时还没有门店');
    }
    });

    }});

  • 相关阅读:
    Selenium + WebDriver 各浏览器驱动下载地址
    selenium之 文件上传所有方法整理总结【转】
    FakeUserAgentError('Maximum amount of retries reached') 彻底解决办法
    git关联远程仓库
    通过chrome console 快速获取网页连接
    【转】Selenium
    【转】fiddler抓包HTTPS请求
    【转】Wireshark和Fiddler分析Android中的TLS协议包数据(附带案例样本)
    php 通过 create user 和grant 命令无法创建数据库用户和授权的解决办法
    差等生也是需要交卷的
  • 原文地址:https://www.cnblogs.com/smght/p/5163185.html
Copyright © 2020-2023  润新知