7
回答
为啥都获取到了数据但就是不能循环出来呢
注册华为云得mate10,2.9折抢先购!>>>   
{code: 200, datas: [{goods: {title: "女u8fy",…}}]}
code:200
datas:[{goods: {title: "女u8fy",…}}]
0:{goods: {title: "女u8fy",…}}
goods:{title: "女u8fy",…}
item:[{goods_id: "237", goods_name: "数据11", goods_promotion_price: "44.00", goods_price: "44.00",…},…]
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}
title:"女u8fy"    

上面是ajax获取到的json

但就是循环不出来,循环代码如下

<script type="text/html" id="goods">
	<div class="nctouch-home-block item-goods">
	<% if (title) { %>
		<div class="tit-bar"><%= title %></div>
	<% } %>
		<ul class="goods-list">
		<% for (var i in item) { %>
			<li>
				<a href="tmpl/product_detail.html?goods_id=<%= item[i].goods_id %>">
					<div class="goods-pic"><img src="<%= item[i].goods_image %>" alt=""></div>
					<dl class="goods-info">
						<dt class="goods-name"><%= item[i].goods_name %></dt>
						<dd class="goods-price">¥<em><%= item[i].goods_promotion_price %></em></dd>
					</dl>
				</a>
			</li>
		<% } %>
		</ul>
	</div>
</script> 




PHP
举报
lghyt
发帖于2年前 7回/328阅
共有7个答案 最后回答: 2年前
你需要从返回的json数据中,先把item弄出来
--- 共有 1 条评论 ---
lghyt其实你说的对,后来我查了一下,是json返回来的数值少了很多,所以不能加载。 2年前 回复

item:[{goods_id: "237", goods_name: "数据11", goods_promotion_price: "44.00", goods_price: "44.00",…},…]
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}



json 返回数据格式有问题

不应该是这样吗?:

item:[
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}]

--- 共有 1 条评论 ---
lghytjson数据没问题 2年前 回复

引用来自“bodii”的评论

item:[{goods_id: "237", goods_name: "数据11", goods_promotion_price: "44.00", goods_price: "44.00",…},…]
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}



json 返回数据格式有问题

不应该是这样吗?:

item:[
0:{goods_id: "237", goods_name: "数据22", goods_promotion_price: "44.00", goods_price: "44.00",…}
1:{goods_id: "236", goods_name: "数据4444", goods_promotion_price: "33.00", goods_price: "33.00",…}]

1. 我没有在php 中见过这种写法:for  (var i in item) ??????
2.我没有在json 格式中遍历过这种: item:[{...}]0:...1:... ????? 
3.你应该是遍历item吧,既然遍历item, 你的 i 就应该是键,而item应该是类似:                                      "singers":[ {'id':02,'name':'tom','gender':'男',...},... ] 的格式??????
我没看错吧?  ajax获取的东西是客户端的,你竟然用服务端的东西循环客户端的咚咚,,,,<% %>不是 jsp的写法吗 ?
顶部