码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-08-03 15:06:25      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   os   io   for   cti   

<!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: "French" },
				{ name: "German" },
				{ name: "Spanish" }
            ]
        };

        $("#movieList").html(
            $("#movieTemplate").render(movie)
        );
    </script>
</body>
</html>

  

JsRender系列demo(9)自定义函数,布布扣,bubuko.com

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

标签:style   blog   http   java   os   io   for   cti   

原文地址:http://www.cnblogs.com/alphafly/p/3888295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!