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 ...
随机推荐
- 设置iframe内表单target属性以兼容IE、Firefox【转载】
设置iframe内表单target属性以兼容IE.Firefox[转载] 2011年11月19日 haibor 今天有客户反应,在一产品网站的资源下载页面,用户登录提交后页面无反应! 经测 ...
- [译]JavaScript需要类吗?
[译]JavaScript需要类吗? 原文:http://www.nczonline.net/blog/2012/10/16/does-javascript-need-classes/ 译者注:在 ...
- PyTorch源码解读之torchvision.models(转)
原文地址:https://blog.csdn.net/u014380165/article/details/79119664 PyTorch框架中有一个非常重要且好用的包:torchvision,该包 ...
- maven下载与配置环境变量
1.打开maven官网下载 http://maven.apache.org/download.cgi 下载 解压(这里博主放在D盘下) 2.配置环境变量 验证是否配置成功 3.本地仓库配置
- Mybatis中传参包There is no getter for property named 'XXX' in 'class java.lang.String'
Mybatis中传参包There is no getter for property named 'XXX' in 'class java.lang.String' 一.发现问题 <select ...
- 如何将JS里变量的值赋给文本框
举个栗子: <html><HEAD><script type="text/javascript" language="Javascript1 ...
- python的变量,对象的内存地址以及参数传递过程
作为一个由c/c++转过来的菜鸟,刚接触Python的变量的时候很不适应,应为他的行为很像指针,void* ,不知道大家有没有这样的感觉.其实Python是以数据为本,变量可以理解为标签.作为c/c+ ...
- quartz动态job工具类 serviceh注入问题
package com.heyi.yanglao.common.job.util; import cn.hutool.core.date.DateUtil; import lombok.extern. ...
- jQuery实际案例⑥——图片跟随鼠标、五角星评分案例
一.图片跟随鼠标移动 1.要求:鼠标移动到哪,图片就要跟到哪 2.用到的事件:首先监听鼠标:$(document).mousemove(function(event){ }); //此时可以获取鼠标距 ...
- [Vue]组件——.sync 修饰符实现对prop 进行“双向绑定”
一.同时设置1个 prop 1.以 update:my-prop-name 的模式触发事件,如对于title属性: this.$emit('update:title', newTitle) 2.然后父 ...