
1 lyxint 2012-04-24 21:26:13 +08:00 |
2 airyland 2012-04-24 21:27:17 +08:00 文本模板用<script type="text/template" id="template">some html {{data}}</script>写在html里。 用mustache之类的模板引擎render。 |
3 catfan 2012-04-24 21:37:11 +08:00 使用此方法建立fragment var frag = document.createDocumentFragment(); 在里面塞元素: frag.appendChild(xxx); 然后把它append到需要的地方 document.getElementById('wrap').append(frag); |
4 turing 2012-04-24 21:40:21 +08:00 https://github.com/janl/mustache.js +1 使用有规则数据源,确定好DOM结构后按需渲染。 |
5 jjlovegrape 2012-04-24 21:47:41 +08:00 https://github.com/janl/mustache.js +1,在最近的一个项目中使用了mustache,感觉很KISS,配合backbone使用效果更佳。 http://coenraets.org/blog/2011/12/tutorial-html-templates-with-mustache-js/ 这边是个mustache.js的 tutorial,可能要翻墙。 |
6 rociiu 2012-04-24 21:47:56 +08:00 可以看看 backbone (http://documentcloud.github.com/backbone/) 轻量的前端MVC框架 |
10 POPOEVER 2012-04-24 21:55:02 +08:00 其实我跟你一样,我更懒,直接用 jQuery 的 html()+prepend() =_= |
11 tioover 2012-04-24 22:10:22 +08:00 看了一下mustache 语法会和服务端的冲突,怎么解决? |
12 jjlovegrape 2012-04-24 22:13:51 +08:00 @tioover 为什么会和服务端冲突呢?比较好的方式是,从服务端读取了JSON,然后render模板,模板支持用函数的方法填充,填充可以是{{someFunctiion}},这个函数里处理你想要的数据。{{{}}}这样使用填充的内容不会变转移。 |
13 lene 2012-04-24 22:18:48 +08:00 介不似那个谁么?学习学习~~~ |
15 tioover 2012-04-24 22:29:28 +08:00 @jjlovegrape 也对…… |
18 paulguo 2012-08-30 22:34:31 +08:00 可以尝试下 Juicer(榨汁机,模板引擎 by Taobao UED):http://juicer.name ,性能较 Mustache 等出众很多。 |
19 kernel1983 2012-08-30 23:43:02 +08:00 js template, 由于现在underscore.js已经是标配, 直接用它内置的 backbone依赖underscore, 但是我不依赖backbone |
20 bitsmix 2012-08-30 23:52:53 +08:00 t.js 也不错。 |