js循环子节点问题

https://img4.mukewang.com/5c9c799e0001392e03940685.jpg

https://img1.mukewang.com/5c9c799f0001385c07450459.jpg

https://img.mukewang.com/5c9c799f00012df505180674.jpg

https://img.mukewang.com/5c9c79a00001d2d003920687.jpg

循环数组每个里子节点的值 不知道怎么回事每次拿到的值要么是最后的子节点的值,要么就是一起相加的值

哈士奇WWW
浏览 457回答 3
3回答

浮云间

$.ajax({&nbsp; &nbsp; type:"GET",&nbsp; &nbsp; url:"json/index.json",&nbsp; &nbsp; async:true,&nbsp; &nbsp; success: function (data) {&nbsp; &nbsp; &nbsp; &nbsp; let list = '';&nbsp; &nbsp; &nbsp; &nbsp; for (let i in data.data) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //子节点循环&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let pic = '';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let line = data.data[i].picurl&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (let x in line) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pic += `<div class="image"><img src="${data.data[i].picurl[x].pic}"></div>`&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list += `<li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="javascript:">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="list_top flex">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="head-time f1">${data.data[i].time}</div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="head-true_false f1">${data.data[i].state}</div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="content_img">${pic}</div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="footer">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="number_monet">共${data.data[i].numbers}件商品,实付<span class="money">¥${data.data[i].money}</span></div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="fd">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <object><a href="javascript:" class="btn">${data.data[i].btn}</a></object>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </li>`;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; $('.list_ul').prepend(list)});

月关宝盒

应该把第二个循环放到第一个循环的里面。for (let i in data.data) {&nbsp; y = i;&nbsp; ...&nbsp; let line = ...&nbsp; for (let x in line)}

慕的地8271018

这么简单的逻辑错误!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript