Underscore template
/*********************************************************************
* Underscore template
* 说明:
* 在找JavaScript数据处理lib的时候,找到Underscore,细读一下其开发文档,
* 发现里面有template处理,对比了一下Handlebars,感觉Underscore更适合目前使
* 用,主要是目前足够了。
*
* 2017-8-28 深圳 龙华樟坑村 曾剑锋
********************************************************************/ 一、参考文档:
. Underscore
http://underscorejs.org/
. Underscore template
http://www.bootcss.com/p/underscore/#template
. UnderscoreJS精巧而强大工具包
http://blog.fens.me/nodejs-underscore/
. underscore templates - JSFiddle
https://jsfiddle.net/casiano/LS384/ 二、template demo:
<!-- Install jQuery and underscore --> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script> <!-- Create your template -->
<script type="foo/bar" id='usageList'>
<table cellspacing='' cellpadding='' border='' >
<thead>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<%
// repeat items
_.each(items,function(item,key,list){
// create variables
var f = item.name.split("").shift().toLowerCase();
%>
<tr>
<!-- use variables -->
<td><%= key %></td>
<td class="<%= f %>">
<!-- use %- to inject un-sanitized user input (see 'Demo of XSS hack') -->
<h3><%- item.name %></h3>
<p><%- item.interests %></p>
</td>
</tr>
<%
});
%>
</tbody>
</table>
</script> <!-- Create your target --> <div id="target"></div> <!-- Write some code to fetch the data and apply template --> <script type="text/javascript">
var items = [
{name:"Alexander", interests:"creating large empires"},
{name:"Edward", interests:"ha.ckers.org <\nBGSOUND SRC=\"javascript:alert('XSS');\">"},
{name:"..."},
{name:"Yolando", interests:"working out"},
{name:"Zachary", interests:"picking flowers for Angela"}
];
var template = $("#usageList").html();
$("#target").html(_.template(template,{items:items}));
</script>
Underscore template的更多相关文章
- require.js+knockout.js+.underscore模板引擎的使用
第一种使用方式: HTML: <ul data-bind="template: { name: 'peopleList' }"></ul> <scri ...
- 深入解析Backbone.js框架的依赖库Underscore.js的作用
这篇文章主要介绍了深入解析Backbone.js框架的依赖库Underscore.js的作用,用过Node.js的朋友对Underscore一定不会陌生:)需要的朋友可以参考下 backbone必须依 ...
- TodoMVC中的Backbone+MarionetteJS+RequireJS例子源码分析之三 Views
这个版本的TodoMVC中的视图组织划分比较细,更加易于理解,这也得益于Marionette为我们带来了丰富的视图选择,原生的backbone只有views,而Marionette则有itemview ...
- Kubernetes采用CoreDNS
参考文档: kubernetes插件:https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns/coredns 自 ...
- Kubernetes 部署 1.9.7 高可用版
转载于https://codegreen.cn/2018/08/30/kubernetes-cluster-1.9.7/ 前言 在部署之前,首先感谢 手动搭建高可用的kubernetes 集群 博文的 ...
- [Backbone]5. Model & View, toggle between Models and Views -- 2
Dr. Goodparts is pretty flaky and has been cancelling a lot of appointments lately. He's asked for a ...
- [Backbone]3. More detail on View
Change the AppointmentView to have a top-level li tag (instead of the default div tag). var Appointm ...
- kubernetes 之dns 服务发现
1.在每个节点上面导入如下镜像 [root@node1 DNS]# lltotal 59816-rw-r--r--. 1 root root 8603136 Nov 25 18:13 execheal ...
- k8s1.13.0二进制部署-Dashboard和coredns(五)
部署UI 下载yaml文件https://github.com/kubernetes/kubernetes [root@k8s-master1 ~]# git clone https://github ...
随机推荐
- [BZOJ]BST again
Description 求有多少棵大小为n的深度为h的二叉树.(树根深度为0:左右子树有别:答案对1000000007取模) Input 第一行一个整数T,表示数据组数. 以下T行,每行2个整数n和h ...
- 永久更改hostname主机名
vim /etc/sysconfig/network NETWORKING=yesHOSTNAME=keepalived-nginx1GATEWAY=192.168.33.2 vim /etc/hos ...
- NOIP2015 T4 推销员 贪心+堆优化
前几天在学堆,这个数据结构貌似挺简单的,但是我看了很久啊QAQ... 今天算是搞懂了吧...于是想到了这道题...(当初悄悄咪咪看题解记得一点) 点我看题 放洛谷的题... 题意的话,大概就是有n个房 ...
- Flink快速入门
文章目录 1 安装:下载并启动 1.1 下载 1.2 启动一个local模式的Flink集群 2 运行例子 3 集群模式安装 4 Flink on YARN 安装:下载并启动 Flink可以在Linu ...
- 【Semantic segmentation Overview】一文概览主要语义分割网络(转)
文章来源:https://www.tinymind.cn/articles/410 本文来自 CSDN 网站,译者蓝三金 图像的语义分割是将输入图像中的每个像素分配一个语义类别,以得到像素化的密集分类 ...
- Nginx下修改wordpress固定链接后导致访问文章404
假设我的wordpress博客是的 server{}段是直接放到放到了nginx.conf (有的人为了方便管理,都习惯在单独写个vhost/目录来存放每个网站的配置文件,这就要根据你自己的设置来添 ...
- 自定义ajax
// 动态添加script获取里面的数据,,可实现跨域,不跨的当然也可以 getFile:function(params){ try{ //创建script标签 var cbName=params.c ...
- 在 Spark 中使用 IPython Notebook
本文是从 IPython Notebook 转化而来,效果没有本来那么好. 主要为体验 IPython Notebook.至于题目,改成<在 IPython Notebook 中使用 Spark ...
- 使用 Python 在 Caché 和 Sql Server 之间同步数据
任务目标:抽取 Caché 中的数据,导入 Sql Server 中. 遇到的问题: 1.UnicodeEncodeError: ‘ascii’ codec can’t encode characte ...
- keepalived与nginx安装
目的: 当用户请求访问时,会通过nginx来访问web服务应用,因此我们必须要保证nginx的高可用,要保证nginx的高可用,我们需要通过keepalived来监控nginx,并对外提供1个虚拟的v ...