欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mint UI實(shí)現(xiàn)A-Z字母排序的城市選擇列表

 更新時(shí)間:2018年12月28日 14:10:16   作者:豆i漿  
這篇文章主要為大家詳細(xì)介紹了Mint UI實(shí)現(xiàn)A-Z字母排序的城市選擇列表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Mint Ul實(shí)現(xiàn)A-Z字母排序的城市選擇列表的具體代碼,供大家參考,具體內(nèi)容如下

效果圖如下:

項(xiàng)目文件存放路徑圖:

pinying.js 和 city.json文件下載傳送門

所有代碼如下:

<template>
  <mt-index-list>
    <mt-index-section v-for="letter in citySortArr" :key="letter" :index="letter">
      <mt-cell v-for="cityName in cityArr" :key="cityName" v-if="cityName.key == letter" :title="cityName.value "></mt-cell>
    </mt-index-section>    
  </mt-index-list> 
</template>

<script>
import city from "../assets/json/city"http://導(dǎo)入所有城市的JSON
import { makePy } from "../assets/js/pinying"http://導(dǎo)入插件獲取所有城市中文的大寫首字母

export default {
 data () {
  return {
   arr: [],//存放初始篩選的城市名稱
   cityArr: [],//存放第二次篩選后所有城市名稱
   citySort: [],//存放初始獲取城市首字母大寫的數(shù)組
   citySortArr: []//存放第二次篩選重復(fù),不存在的城市首字母數(shù)組
  };
 },
 created () {

  /**
   * 將json數(shù)據(jù)中的無用數(shù)據(jù)剔除
   */
  for (let i in city) {
   if (city[i].name != "請選擇") {//將第一層數(shù)據(jù)中為 “請選擇” 的剔除掉
    this.arr.push(city[i].name);
    for (let j in city[i].sub) {//將第二層數(shù)據(jù)中為 “請選擇 和 其他” 的剔除掉
     if (
      city[i].sub[j].name != "請選擇" &&
      city[i].sub[j].name != "其他"
     ) {
      this.arr.push(city[i].sub[j].name);//將處理后的數(shù)據(jù)存放在數(shù)組中,等待第二次篩選處理
     }
    }
   }
  }

  /**
   * 配置相關(guān)數(shù)據(jù)
   */
  for (let k in this.arr) {
   let cityKey = makePy(this.arr[k])[0].substring(0, 1);//獲取每一個(gè)市區(qū)的首字母
   let cityValue = this.arr[k];//獲取所有市區(qū)
   this.citySort[cityKey] = cityKey;//利用對象特性,剔除重復(fù)的字母,并將剔除后的字母存進(jìn)對象中

   //將所有市區(qū)信息 以( 字母 - 市區(qū)名 )的格式存在至數(shù)組中
   this.cityArr[k] = {
    key: cityKey,
    value: cityValue
   };
  }

  /**
   * 將處理后的首字母數(shù)據(jù)對象,存放至數(shù)組中
   */
  for (let p in this.citySort) {
    this.citySortArr.push(this.citySort[p]);
  }

  /**
   * 將真實(shí)存在的市區(qū)首字母按A-Z進(jìn)行排序
   */
  this.citySortArr = this.citySortArr.sort();

 }
};
</script>

<style>
.mint-cell-title {
  flex: 0 0 auto;
}

.mint-indexsection-index {
  text-align: left;
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論