Home  >  Article  >  Web Front-end  >  Introducing the usage examples of jquery.mustache.js

Introducing the usage examples of jquery.mustache.js

零下一度
零下一度Original
2017-06-17 17:53:352835browse

jquery.mustache is encapsulated with jQuery and provides the following methods to make template use more convenient.
1, three ways to add templates

add,

addFromDom

addFromString

You can add templates directly, whether as String Text or reference to other DOM elements

(1) template is a string literal

//add仅仅是把template添加到当前页面,注意并没有渲染
$.Mustache.add('string-template', '<p>Hi, {{name}}, this is an inline template<p>');

(2) Reference to DOM element addFromDom

// 两者是相同的,后者有更简洁的语法 These two are identical, the latter just provides a terser syntax.
$.Mustache.add('dom-template', $('#dom-template').html());
$.Mustache.addFromDom('dom-template');

If you prefer to store the templates in the DOM (assuming they are loaded from an external file), then you can just call

$.Mustache.addFromDom() without any parameters, that way Will read all