jsrender 学习 入门 demo

1.引入我们所需要的js包

<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript" src="js/jsrender-min.js"></script>

2.编写我们要输出内容的div

<div id="result"></div>

3.编写我们的数据

<script>
var data = [
	{
		"title":	"山水图",
		"imgpath":"http://pic17.nipic.com/20111111/7953751_140357624000_2.jpg",
		'alink':"http://pic17.nipic.com/20111111/7953751_140357624000_2.jpg",
		"showPic":true
	},{
		"title":	"山水画",
		"imgpath":"http://pic29.nipic.com/20130525/8960079_091008529373_2.jpg",
		'alink':"http://pic29.nipic.com/20130525/8960079_091008529373_2.jpg",
		"showPic":true
	}
];
var templates = $.templates("#contentarea");
var htmlOutput = templates.render(data);
$("#result").html(htmlOutput);
</script>


4.编写我们遍历的div布局

<script type="text/jsrender" id="contentarea">
	<div class="content">
		<em>name:</em>{{:title}}
		{{if showPic && imgpath }}
			<a href={{:alink}} target='_blank'> <img src='{{:imgpath}}' width='100' height='100' /></a>
		{{/if}}
	</div>
</script>

(注:3和4的顺序可以颠倒过来)



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值