Below I will share with you a method of implementing Chinese A-Z sorting in vue.js or js. It has a good reference value and I hope it will be helpful to everyone.
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<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);//截取第一个字符 if(arrList[j].charAt(0)==letters[i]||arrList[j].charAt(0)==letters[i].toLowerCase()){ //首字符是英文的 curr.data.push(arrList[j]); }else if(zh[i]!='*'&&$this.isChinese(initial)){ //判断是否是无汉字,是否是中文 if(initial.localeCompare(zh[i]) >= 0 &&(!zh[i+1]||initial.localeCompare(zh[i+1]) <0)) { //判断中文字符在哪一个类别 curr.data.push(arrList[j]); } } } }else{ for(var k =0;k<arrList.length;k++){ var ini = arrList[k].charAt(0); //截取第一个字符 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); //排序,英文排序,汉字排在英文后面 //}); } } 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 into an array, and call it directly in vue ->this.pySort(arr); js can directly call the pySort(arr) method. Achieve sorting according to the format of A-Z
The format shown in the console output is as shown below:
letter Store key values A-Z
data: store the sorted array
As for vue, which needs to be placed on the page, use v-for loop v-for="(key, value) in arr"
You need to get the value of the data array, continue to use v-for="tmp in (key.data)" to loop in the elements you want to enter and place
It is relatively simple to write , this method is also common in js
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Use vue element-ui ajax technologies to implement an example of a table
##Utilization How does live-server set up a local server and automatically refresh? What are the specific methods?
Solve the problem that lower version browsers do not support the import of es6
##
The above is the detailed content of How to implement Chinese A-Z sorting in vue.js or js. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools