jtemplate之#foreach嵌套使用

1.首先看一下我们的json数据:

[
	{"goodsId":22,"goodsSn":"111","goodsName":"ppp",
	  "simplyGoodsSizes":[
		{"id":30,"newPrice":44,"sizeStr":"4*4"},
		{"id":28,"newPrice":22,"sizeStr":"2*2"}
	   ]
	},
	{"goodsId":22,"goodsSn":"111","goodsName":"ppp",
	  "simplyGoodsSizes":[
		{"id":32,"newPrice":123,"sizeStr":"6*6"},
		{"id":258,"newPrice":456,"sizeStr":"7*7"}
	   ]
	}
]

 

 

2.模板文件:

<textarea id="goods_result_template" style="display: none">
	<table>
		<tr>
			<td>产品id</td>
			<td>产品货号</td>
			<td>产品名称</td>
			<td>产品尺寸</td>
			<td></td>
		</tr>
		{#foreach $T as record}
		<tr>
			<td>{$T.record.goodsId}</td>
			<td>{$T.record.goodsSn}</td>
			<td>{$T.record.goodsName}</td>
			<td>
				{#foreach $T.record.simplyGoodsSizes as goodsSize}
					{$T.goodsSize.sizeStr}
				{#/for}	
			</td>
			<td>
				<input type="button" value="将这个货加入订单"
					οnclick="selThisGoods(this);" />
			</td>
		</tr>
		{#/for}
	</table>
</textarea>

 

 

3.附件数据:

$("#goods_result_dialog").setTemplateElement("goods_result_template");
   // 给模板加载数据
$("#goods_result_dialog").processTemplate(json);//

 注意上面的json数据为服务器返回的json对象,格式为1中所示的数据格式.

 

注意上面的这一段的嵌套写法:

{#foreach $T.record.simplyGoodsSizes as goodsSize}
					{$T.goodsSize.sizeStr}

{#/for}

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值