简体   繁体   中英

How to get values of child element on Array multiple dimension of JSON by Jquery

i have issued with array JSON. i have try many time but didn't work.

//i put my code to there, kindly help me debug it.

the string json

> {"resultUser":[{"username":"quyennv","email":"quyencl@hotmail.com","userlevel":0,"datecreate":"20/03/2019
> 12:00:00
> AM","status":1},{"username":"sample","email":"sameple@hotmail.com","userlevel":1,"datecreate":"20/03/2019
> 12:00:00 AM","status":1}]}

and here is code for view element in array

 var datax = {"resultUser":[{"username":"quyennv","email":"quyencl@hotmail.com","userlevel":0,"datecreate":"20/03/2019 12:00:00 AM","status":1},{"username":"sample","email":"sameple@hotmail.com","userlevel":1,"datecreate":"20/03/2019 12:00:00 AM","status":1}]}; var userTbl = $('#listUser tbody').empty(); $.each(datax.resultUser,function (index) { index += 1; userTbl.append('<tr><td>' + this.username + '</td><td>' + this.email + '</td><td>' + this.userlevel + '</td><td>' + this.datecreate + '</td><td>' + this.status + '</td></tr>'); }); 
 table,td{ border:1px solid #000; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <body> <table id="listUser"> <thead ><tr><td>Username</td><td>Email</td><td>User Level</td><td>Date Created</td><td>User status</td></tr></thead> <tbody> </tbody> </table> </body> 

kindly help me solve this issue. thanks a lot

===== Updated. i need more details element inside the each loop change datax to datax.resultUser

Change data to datax.resultUser in $.each to loop through array of resultUser

 var datax = {"resultUser":[{"username":"quyennv","email":"quyencl@hotmail.com","userlevel":0,"datecreate":"20/03/2019 12:00:00 AM","status":1},{"username":"sample","email":"sameple@hotmail.com","userlevel":1,"datecreate":"20/03/2019 12:00:00 AM","status":1}]}; var userTbl = $('#listUser tbody').empty(); $.each(datax.resultUser,function (index) { index += 1; userTbl.append('<tr><td>' + this.username + '</td><td>' + this.email + '</td><td>' + this.userlevel + '</td><td>' + this.datecreate + '</td><td>' + this.status + '</td></tr>'); }); 
 table,td{ border:1px solid #000; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <body> <table id="listUser"> <thead ><tr><td>Username</td><td>Email</td><td>User Level</td><td>Date Created</td><td>User status</td></tr></thead> <tbody> </tbody> </table> </body> 

 $.each(datax.resultUser, function (index) { index += 1; 
 userTbl.append('<tr><td>' + this.username + '</td><td>' + 
 this.email + '</td><td>' + this.userlevel + '</td><td>' + 
 this.datecreate + '</td><td>' + this.status + '</td></tr>'); }); 

data.resultUser only array you have to itreate that only

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM