JsRender系列demo(5)compline

<!DOCTYPE html>
<html>
<head>
	<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
	<script src="../../jsrender.js" type="text/javascript"></script>
 	<link href="../resources/demos.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a href="../demos.html">JsRender Demos</a><br />

<h3>Accessing paths</h3>

<script id="peopleTemplate" type="text/x-jsrender">

	<b>{{:#index+1}}:</b> {{>firstName}} {{>lastName}}:

	<br/>
	{{for address tmpl="#addressTemplate"}}{{else}}
		Address missing
	{{/for}}

	<div>
		Phones:
		{{for ~combine(phones, cells)}}
			<b>{{>#data}}</b> ({{>#parent.parent.data.firstName}}‘s)
		{{else}}
			{{>#parent.data.firstName}} has no phones or cells
		{{/for}}

{{!-- or provide an alias to get to firstName from nested content
		Phones:
		{{for ~combine(phones, cells) ~frstNm=firstName}}
			<b>{{>#data}}</b> ({{>~frstNm}}‘s)
		{{else}}
			{{>~frstNm}} has no phones or cells
		{{/for}}
--}}
	</div>

	<br/>

	<i>
		{{>firstName}}

		{{if address && address.street}}  {{!-- address may be null or undefined --}}
			lives in {{>address.street}}.
		{{else}}
			has no address...
		{{/if}}
	</i>
	<hr/>

</script>

<script id="addressTemplate" type="text/x-jsrender">
<div>
	{{if street}}
		{{>street}}
	{{else}}
		<i>Somewhere</i> in
	{{/if}}
	{{>city}}
</div>
</script>

<div id="peopleList"></div>

<script type="text/javascript">
	var people = [
		{
			firstName: "Pete",
			lastName: "Ruffles",
			address: {
				city: "Bellevue"
			},
			cells: ["425 666 3455", "425 222 1111"]
		},
		{
			firstName: "Xavier",
			lastName: "NoStreet",
			phones: ["222 666 3455"],
			cells: ["444 666 3455", "999 222 1111"]
		},
		{
			firstName: "Christie",
			lastName: "Sutherland",
			address: {
				street: "222 2nd Ave NE",
				city: "Redmond"
			}
		}
	];

	$.views.tags({
		notLast: function( content ) {
			var array = this.parent.data;
			return array[ array.length - 1 ] === this.data ? "" : content( this );
		}
	});

	$.views.helpers({
		combine: function( arr1, arr2 ) {
			return arr1 && arr2 ? arr1.concat(arr2) : arr1 || arr2;
		}
	});

	$( "#peopleList" ).html(
		$( "#peopleTemplate" ).render( people )
	);

</script>

</body>
</html>

  

JsRender系列demo(5)compline

时间: 2025-01-02 01:40:01

JsRender系列demo(5)compline的相关文章

JsRender系列demo(6)-无名

<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.js" type="text/javascript"></script> <script src="../../jsrender.js" type="text/javascript"></script>

JsRender系列demo(5) for else

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascrip

JsRender系列demo(3)-自定义容器

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascrip

JsRender系列demo(4)-if else

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascrip

JsRender系列demo(9)自定义函数

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascrip

JsRender系列demo(2)多模板-template

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascrip

JsRender系列demo(1)-insert-data

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript

JsRender系列-11

<!DOCTYPE html> <html> <head> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery-ui.js"></script> <script

自定义View之大风车系列demo(一)

每次写博客最讨厌写博客的开头,不知道该写些什么,现在也是,感觉跟写八百字作文似的.之所以会写这一系列的demo是因为前天看网上的一个图片转圈的源码的时候 突发奇想要不要自己也弄个耍耍,顺便学习下view的相关知识!说干就干,当然自己写的时候也不免参照写别人得到代码,毕竟自定义view与我的水平来说确实具有挑战性,通过完成这一些列的小demo确实收获颇多,虽然还有些许在我看来更牛逼的功能自己没法实现,但自己的目的也算达到了.先啰嗦了这么多,先说说大风车系列小demo的总体概况:一共五个版本,这也意