How to write Vue foreach array and traverse array in jsScenarioUse Axios in Vue to send get or post requests. When sending requests, you need to use js Traverse and process the request parameters. When receiving a response, you need to traverse and process the response result. Note the difference between foreach arrays in Vue and JS. accomplishIterating over an array in js //Define the shift details array var bcglxiangxiList = new Array(); //Define shift details object var bcxiangxi = {}; // Loop through the parameters bcglXiangXiListParam.forEach(element => { bcxiangxi.xh = element.xh; bcxiangxi.bcbh = data.bcbh; bcxiangxi.dkkssj = element.sjfw[0]; bcxiangxi.dkjssj = element.sjfw[1]; bcxiangxi.ts = element.ts; bcxiangxi.dkdd = element.dkdd; bcxiangxi.zxjxljsj = element.jxsjfw[0]; bcxiangxi.zdjxljsj = element.jxsjfw[1]; //Store the shift details object into the shift details array bcglxiangxiList.push(bcxiangxi); }); Iterating over an array in vue var bcglxiangxiList = new Array(); var bcxiangxi = {}; debugger; if ( response.data.bcglXiangXiList != null && response.data.bcglXiangXiList.length > 0 ) { console.log(response.data.bcglXiangXiList); response.data.bcglXiangXiList.forEach((item, index) => { console.log(item); bcxiangxi.xh = item.xh; bcxiangxi.bcbh = item.bcbh; //debugger bcxiangxi.sjfw = new Array(); bcxiangxi.sjfw[0] = item.dkkssj; bcxiangxi.sjfw[1] = item.dkjssj; bcxiangxi.ts = item.ts; bcxiangxi.dkdd = item.dkdd; bcxiangxi.jxsjfw = new Array(); bcxiangxi.jxsjfw[0] = item.zxjxljsj; bcxiangxi.jxsjfw[1] = item.zdjxljsj; bcglxiangxiList.push(bcxiangxi); }); } You can see that the traversal method is the same. In js, you can also use the traversal method with two parameters. //Define the shift details array var bcglxiangxiList = new Array(); //Define shift details object var bcxiangxi = {}; // Loop through parameters bcglXiangXiListParam.forEach((element,index) => { bcxiangxi.xh = element.xh; bcxiangxi.bcbh = data.bcbh; bcxiangxi.dkkssj = element.sjfw[0]; bcxiangxi.dkjssj = element.sjfw[1]; bcxiangxi.ts = element.ts; bcxiangxi.dkdd = element.dkdd; bcxiangxi.zxjxljsj = element.jxsjfw[0]; bcxiangxi.zdjxljsj = element.jxsjfw[1]; //Store the shift details object into the shift details array bcglxiangxiList.push(bcxiangxi); }); vue forEach loop usage//data is a collection data.forEach(function(item, index) { //item is the object that is looped on that day //index is the loop index, starting from 0}) The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: CentOS 8 Installation Guide for Zabbix 4.4
>>: Detailed explanation of grep and egrep commands in Linux
Table of contents Understand the core concept of ...
In CSS, text is one of the most common things we ...
mysql master-slave configuration 1. Preparation H...
1. Caches - Query Cache The following figure is p...
Problem to be solved Mainly for cross-level commu...
Without further ado, let's take a look at the...
The machines in our LAN can access the external n...
1. Introduction to Docker Docker is developed in ...
The most understandable explanation of the accura...
Linux Operation Experimental environment: Centos7...
Without further ado, I will post the code for you...
introduction Sometimes, if there are a large numb...
Table of contents 1. Bootstrap Grid Layout 2. Ver...
The parent node of the parent node, for example, t...
Vue methods and properties 1. Methods Usage 1 met...