JS中art-template模板使用if判断

JS代码:

	// json数据
	var json=[
		{
			"id": 1,
			"good_sign": 2,
			"good_img": "http://dummyimage.com/460x440/ee79f2/79f2cb.png&text=商品\n"
		},
		{
			"id": 2,
			"good_sign": 1,
			"good_img": "http://dummyimage.com/460x440/f2a779/8479f2.png&text=商品\n"
		},
		{
			"id": 3,
			"good_sign": 0,
			"good_img": "http://dummyimage.com/460x440/91f279/f279b4.png&text=商品\n"
		},
		{
			"id": 4,
			"good_sign": 1,
			"good_img": "http://dummyimage.com/460x440/79d7f2/f2e979.png&text=商品\n"
		}
	]
	// 渲染json
	$("#container").html(template("indexmain",json));

HTML代码:

	<div id="container">div>
	
	<script type="text/html" id="indexmain">
		<!-- 商品列表 -->
		<ul>
			{{each list item}}
			<li>
				<a href="javascript:;">
					{{if item.good_sign==1}}
					<div class="ico-comm i-mark">
						 <span>新品</span>
					</div>
					{{else if item.good_sign==2}}
					<div class="ico-comm i-mark">
						 <span>热卖</span>
					</div>
					{{/if}}
					<img src="{{item.good_img}}" alt="商品图">
				</a>
			</li>
			{{/each}}
		</ul>
	script>	

效果图:
JS中art-template模板使用if判断_第1张图片

你可能感兴趣的:(Demo,JS,art-template,Demo,javascript,模板引擎,if判断)