Home  >  Article  >  Web Front-end  >  How to implement A-Z sorting of Chinese Pinyin in js

How to implement A-Z sorting of Chinese Pinyin in js

php中世界最好的语言
php中世界最好的语言Original
2018-04-11 16:07:552763browse

This time I will show you how to implement the A-Z sorting of Chinese Pinyin in js, and what are the precautions for implementing the A-Z sorting of Chinese Pinyin in js. The following is a practical case, let's take a look.

To implement Chinese according to the A-Z method, you can write in the methods of vue:

methods:{
        pySort:function(arr,empty){
          var $this = this;
          if(!String.prototype.localeCompare)
            return null;
          var letters = "ABCDEFGHJKLMNOPQRSTWXYZ".split('');
          var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split('');
          var arrList = [];
          for(var m =0;m= 0 &&(!zh[i+1]||initial.localeCompare(zh[i+1]) <0)) {  //判断中文字符在哪一个类别
                    curr.data.push(arrList[j]);
                  }
                }
              }
            }else{
              for(var k =0;k

Convert the jsonobject obtained from php into an array, and call it directly in vue ->this.pySort(arr); js can directly call the pySort(arr) method. Implement sorting in A-Z format

The format shown in the console output is as follows:

The key value A-Z

is stored in letter data: stores the sorted array

As for vue that needs to be placed on the page, use v-for loop v-for="(key, value) in arr"

To get the value of the data array, continue to use v-for="tmp in (key.data)" to loop through the elements you want to enter and place.

The writing is relatively simple, and this method is also common in js

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to deal with the option overlay of select

The vue mobile UI framework implements the side menu plug-in effect

The above is the detailed content of How to implement A-Z sorting of Chinese Pinyin in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn