Vue. js or js to achieve the sorting of Chinese A-Z, vue. jsjs Chinese a-z
According to the A-Z method, you can write in the vue's methods:
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 <arr. length; m ++) {arrList. push (arr [m]. name);} var result = []; var curr; for (var I = 0; I <letters. length; I ++) {curr = {letter: letters [I], data: []}; if (I! = 26) {for (var j = 0; j <arrList. length; j ++) {var initial = arrList [j]. charAt (0); // capture the first character if (arrList [j]. charAt (0) = letters [I] | arrList [j]. charAt (0) = letters [I]. toLowerCase () {// the first character is English curr. data. push (arrList [j]);} else if (zh [I]! = '*' & $ This. isChinese (initial) {// determines whether there are no Chinese characters and whether it is a Chinese if (initial. localeCompare (zh [I])> = 0 &&(! Zh [I + 1] | initial. localeCompare (zh [I + 1]) <0) {// determines the category of the Chinese character, curr. data. push (arrList [j]) ;}}} else {for (var k = 0; k <arrList. length; k ++) {var ini = arrList [k]. charAt (0); // capture the first character if (! $ This. isChar (ini )&&! $ This. isChinese (ini) {curr. data. push (arrList [k]) ;}} if (empty | curr. data. length) {result. push (curr); // curr. data. sort (function (a, B) {// return B. localeCompare (a); // sorting; English sorting; Chinese characters are placed behind English; //}) ;}return result ;}, isChinese: function (temp) {var re =/[^ \ u4E00-\ u9FA5]/; if (re. test (temp) {return false;} return true;}, isChar: function (char) {var reg =/[A-Za-z]/; if (! Reg. test (char) {return false;} return true ;}}
Convert the json object obtained from php to an array, and call-> this. pySort (arr); js directly calls the pySort (arr) method to sort by A-Z format.
For example, the output format on the console:
Key Value A-Z in letter
Data: stores sorted arrays.
As for the vue to be placed on the page, use the v-for loop to v-for = "(key, value) in arr"
To obtain the value of the data array, continue to use v-for = "tmp in (key. data)" to loop through the elements you want to enter
This method is also common in js.
I hope this article will help you to sort data ~~~~