mustache

Mustache的使用

心不动则不痛 提交于 2019-12-11 17:41:40
Mustache的简介 Mustache是一个轻逻辑的模板引擎,它是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,通常是标准的HTML文档 Mustache的基本用法 首先需要导入mustache.js文件 mustache渲染形式单一 var html=mustache.render(teamp,data) teamp是一个模板的html,代码如下: var teamp= '<select id="subject" name="subject">'+ '{{#list}}'+ '<option>'+ ' {{name}}'+ '</option>' + '{{/list}}'+ '</select>'+ '<select id="course" name="course">'+ '{{#list}}'+ '<option>'+ ' {{subject}}'+ '</option>' + '{{/list}}'+ '</select>'+ '<div class="btn2">111111</div>' data是一个数据源对象,样例如下: var data={list:[{name:"计算机",subject:["计算机软件","计算机应用技术","计算机科学与技术"]},{name:"化学工程与技术",subject:["化学工程","化学工艺"]},

Embed mustache template into another template

风格不统一 提交于 2019-12-11 16:21:36
问题 I am using Mustache for HTML templates and HoganJS as renderer. My problem is following: I have table template (table, header, body), but also I have template for each TR element of TBODY. All I want is to reuse TR-template in the TABLE-template. Whether it possible or not? Sample code: <!-- Row Template --> <script type="text/html" id="table_row_template"> <tr> <td><input type="text" name="Name" class="item-name autocomplete-groups" value="{{name}}" /></td> <td><input type="text" name="count

Mustache Templating adding condition

☆樱花仙子☆ 提交于 2019-12-11 15:49:59
问题 Hello Im new to modular javascript programming and templating and Im builiding templates out of my previous code of a slideShow module The code is like <section id="slideShow"> <ul> <li> <img src="..." alt=""> <a href="..."> <h1 class="slideShowTitle">...</h1> <p class="slideShowDate">...</p> <p class="slideShowDetail">...</p> </a> </li> <li> <img src="..." alt=""> <a href="..."> <h1 class="slideShowTitle">...</h1> <p class="slideShowDate">...</p> <p class="slideShowDetail">...</p> </a> </li>

How to use jQuery built in functions in Mustache template

时光毁灭记忆、已成空白 提交于 2019-12-11 13:18:48
问题 I have a mustache.js template <script id="catagorie_list" type="text/template"> {{#rows}}<li><a href="#">{{catagorie_name}}</a></li>{{/rows}} </script> in it, I want to make first letter of each {{catagorie_name}} as Capital Letter. Example: india --> India australia-->Australia Is it possible? 回答1: Supposing the input object is: var countries = { "rows": [ { "catagorie_name": "india" }, { "catagorie_name": "australia" }, { "catagorie_name": "spain" } ] }; We append a function to it: var func

Pattern Lab Templates

最后都变了- 提交于 2019-12-11 11:48:22
问题 I'm pretty new to Pattern Lab, but I feel like if this isn't a feature, it should be. Essentially, I want to model Pattern Labs after a real site. In most (or many) real sites it's common to use a templating engine. This is true of any mainstream technology I've used (rails, django, ASP.Net, or node with handlebars) to manage the view layer. I'll use handlebars in this example because it most closely mirrors the Pattern Lab mustache syntax. One of the big powers of templating engines is

How can accomplish For-Each loop from the underscore template to mustache

大憨熊 提交于 2019-12-11 09:43:23
问题 I have an underscore template and I have to use Mustache to render it. Below is my underscore template: <div id="sub-account"> <p>something</p> <table> <tr><td>Name</td> </tr> <tbody> <% _.each(accountList, function(account) { %> <tr> <td><%= account.get('name') %></td> </tr> <% }) %> </tbody> </table> </div> Im using a mustache as my main view to render a list. How can I loop through the code to render as a mustache template? Backbone Collection: var SubAccountCollection = Backbone

Mustache教程

ぃ、小莉子 提交于 2019-12-11 07:45:05
Mustache教程 一、简介 Mustache 是一个 logic-less (轻逻辑)模板解析引擎,它的优势在于可以应用在 Javascript、PHP、Python、Perl 等多种编程语言中。 二、语法 1. {{keyName}} {{}} 就是 Mustache 的标示符,花括号里的 keyName 表示键名,这句的作用是直接输出与键名匹配的键值 2. {{#keyName}} {{/keyName}} 以 # 开始、以 / 结束表示区块,它会根据当前上下文中的键值来对区块进行一次或多次渲染,如果 {{#keyName}} {{/keyName}} 中的 keyName 值为 null, undefined, false;则不渲染输出任何内容。多用于条件判断。如果keyName是一个列表,则会循环显示。 **3. {{^keyName}} {{/keyName}} ** 该语法与 {{#keyName}} {{/keyName}} 类似,不同在于它是当 keyName 值为 null, undefined, false 时才渲染输出该区块内容。 4. {{.}} {{.}} 表示枚举,可以循环输出整个数组, 5. {{!comments}} ! 表示注释,注释后不会渲染输出任何内容。 6. {{{keyName}}} {{keyName}} 输出会将等特殊字符转译

validate mustache tag value from json file

╄→гoц情女王★ 提交于 2019-12-11 06:40:00
问题 Hi I havent been able to find how to validate a tag before displaying it, for instance: if I have a JSON file lets says this values: { "weeks": [ { "monday800": "no", "monday830": "available", "tuesday800": "available", "tuesday830": "no", "name": "TEST" } ] } I bring the value like this: $(function(){ $.get("data.json",function(data){ var template = $("#tpl").html(); var html = Mustache.to_html(template,data); console.log (); $("#information").html(html); }); }); Now what I want to do is: if

Jquery On() 'click' working on every thing?

别等时光非礼了梦想. 提交于 2019-12-11 04:21:31
问题 Hello I have a problem which drive me crazy :( couldnt figure it out why here is my HTML and Mustache <section id="slideShow"> <script id="slideShow-template" type="text/template"> <ul> {{#slideShow}} <li class="{{{class}}}"> <img src="{{{img}}}" alt="{{{title}}}"> <a href="{{{link}}}"> <h1 class="slideShowTitle">{{title}}</h1> <p class="slideShowDate">{{date}}</p> <p class="slideShowDetail">{{detail}}</p> </a> </li> {{/slideShow}} </ul> <nav> {{#slideShow}} <a href="javascript:;"></a> {{

Mustache.js - How to hook up data?

白昼怎懂夜的黑 提交于 2019-12-11 02:23:30
问题 I like to generate markup and at the same time adding data to nodes in the markup with jQuerys data method Store arbitrary data associated with the matched elements. Is there some way to do that with Mustache or some workaround? See this jsFiddle for code reference: http://jsfiddle.net/fiddlebjoern/edyYu/ 回答1: you could use nested templates as suggested here. Your list item being the second template. Now each time you want to append data run it by your second template and call jquerys append