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
Large Text Data Types in Oracle Clob long text ty...
Let's first look at the MySQL official docume...
I have seen many relevant tutorials on the Intern...
Table of contents Preface ErrorBoundary Beyond Er...
Table of contents 1. A simplest server-side examp...
Some time ago, I submitted a product version to t...
Table of contents The first method: When the MySQ...
Table of contents Multi-table join query Inner Jo...
The default arrangement of text in HTML is horizo...
1. Create a configuration file directory cd /home...
Recently, Docker image pull is very unstable. It ...
There are two types of dead link formats defined b...
For security reasons, MySql-Server only allows th...
Table of contents MySQL's current_timestamp p...
Table of contents 1. Project environment: 2: DNS ...