<!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" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.js"></script>
<script type="text/javascript" src="scripts/jsrender.js"></script>
<link href="scripts/demos.css" rel="stylesheet" />
<link href="scripts/movielist.css" rel="stylesheet" />
</head>
<body>
<script id="movieTemplate" type="text/x-jsrender">
<td>{{>~format(title, "upper")}}</td>//逗号,和“upper”之间一定要空一格
<td>{{for languages}}{{>~format(name, "lower")}}{{/for}}</td>
</script>
<table>
<thead>
<tr>
<th>Title</th>
<th>Languages</th>
</tr>
</thead>
<tbody id="movieList"></tbody>
</table> <script type="text/javascript"> $.views.helpers({
format: function (val, format) {
var ret;
switch (format) {
case "upper": return val.toUpperCase();
case "lower": return val.toLowerCase();
}
}
}); var movie = {
title: "Eyes Wide Shut",
languages: [
{ name: "CHINA" },
{ name: "FRNDH" },
{ name: "HDGD" }
]
}; $("#movieList").html(
$("#movieTemplate").render(movie)
);
</script>
</body>
</html>

  

JsRender系列demo(9)自定义函数的更多相关文章

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

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  2. JsRender系列demo(7)compline

    <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.j ...

  3. JsRender系列demo(6)-无名

    <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.j ...

  4. JsRender系列demo(5) for else

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. JsRender系列demo(4)-if else

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

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

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. JsRender系列demo(1)-insert-data

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  8. PHP函数之自定义函数

    像数学中的函数一样,y=f(x)是函数基本的表达形式,x可看做是参数,y可看做是返回值,即函数定义就是一个被命名的.独立的代码段,它执行特定的任务,并可能给调用它的程序返回一个值. 自定义函数 函数的 ...

  9. Python基础笔记系列九:变量、自定义函数以及局部变量和全局变量

    本系列教程供个人学习笔记使用,如果您要浏览可能需要其它编程语言基础(如C语言),why?因为我写得烂啊,只有我自己看得懂!! 变量在前面的系列中也许就可以发现,python中的变量和C中的变量有些许不 ...

随机推荐

  1. JavaScript ES7 中使用 async/await 解决回调函数嵌套问题

    原文链接:http://aisk.me/using-async-await-to-avoid-callback-hell/ JavaScript 中最蛋疼的事情莫过于回调函数嵌套问题.以往在浏览器中, ...

  2. 如何在Ubuntu下使用TF/SD 卡制作Exynos 4412 u-boot启动盘

    /** ****************************************************************************** * @author    Maox ...

  3. WPF 绑定四(层级绑定)

    xaml: <Window x:Class="WpfApplication1.Window4" xmlns="http://schemas.microsoft.co ...

  4. 在项目中 background transiton 带来的"便利"与“坑”

    本文就两个例子跟大家分享一下background-image与background-size的渐变(transition)所带来的方便与“深坑” 首选,说说这东西好的地方,有时候在做PC项目的时候,可 ...

  5. phpcms v9 源码解析(4)content模块下的index.php文件的init()方法解析

    在了解index.php中的init函数的时候,让我们先看看最开始的几行代码 1-5  第二行, defined('IN_PHPCMS') or exit('Nopermission resource ...

  6. Android:什么是Holo?【Translated By KillerLegend】

    Android:什么是Holo? Martin Brinkmann on May 6, 2013 in Google Android 3 [Translated By KillerLegend] 当你 ...

  7. malloc函数

    C语言中,使用malloc函数向内存中动态申请空间. 函数的原型是extern void *malloc(unsigned int num_bytes); 可见,函数返回的是指针类型,参数是要申请的空 ...

  8. 1095. Cars on Campus (30)

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...

  9. ActiveMQ之selector的用法

    前面的例子中创建一个消息消费者使用的是: sesssion.createConsumer(destination) 另外,还提供了另一种方式: sesssion.createConsumer(dest ...

  10. C# 将cookiecontainer写到本地

    public static void WriteCookiesToDisk(string file, CookieContainer cookieJar) { using(Stream stream ...