---
title: "PURE JavaScript模板库的改进"
author: "imhades"
date: "2008-09-23T20:36:01Z"
tags: ["HTML", "JavaScript", "PHP", "json"]
slug: "pure-javascript"
draft: false
lastmod: "2008-09-23T20:36:01Z"
id: 246063
url: "https://imhades.iteye.com/blog/246063"
---

来源：[OurJS.cn](http://www.ourjs.cn)  原文：[http://www.ourjs.cn/show.php?id=597](http://www.ourjs.cn/show.php?id=597)

 

　　PURE是一个JavaScript的模板引擎。新版本PURE的改进包括：

- 自动表现（auto-rendering）:  新的PURE有了一个新的方法，用于将你的HTML和JSON数据绑定。通过class属性给HTML和JSON数据建立映射。
- 递归模块调用。（要了解更多，可访问[http://beebole.com/pure/getting\_started.html#example6](http://beebole.com/pure/getting_started.html#example6)）
- 事件绑定到HTML。（了解更多，可访问[http://github.com/pure/pure/wikis/attach-events-to-your-html](http://github.com/pure/pure/wikis/attach-events-to-your-html)）
- 改变模块根节点的id
- 能更好地处理字符串值
- 等等

要了解更多这个库的使用方法，可以查看PURE的[官方文档](http://beebole.com/pure/getting_started.html) 。

“自动表现(auto-rendering)”例子：

JAVASCRIPT:

1. $('#hello').autoRender({ "who": "Mary" });}

 

JAVASCRIPT:

01. button.value = 'loading data...';
02. var script = (button.id == 'b4\_2') ?　'js/jsonBig.js':'js/jsonSmall.js';
03. $.getJSON(script, function(context){
04. var directive = {
05. 'tbody tr td\[onclick]':'"clickLine(this)"',
06. 'tbody tr td\[onmouseover]': '"swapStyle(this, true);"',
07. 'tbody tr td\[onmouseout]' : '"swapStyle(this, false);"',
08. 'tbody tr td\[style]':'\\'cursor:pointer\\'',
09. 'tbody tr\[class]+':
10. function(context, items, pos){
11. var oddEven =  (pos % 2 == 0) ? 'even' : 'odd';
12. var firstLast = (pos == 0) ? 'first': (pos == items.length -1) ? 'last':'';
13. return oddEven + ' ' + firstLast; }}
14. $('table.players.2').autoRender(context, directive);
15. button.value = 'Refresh the page to render again';});}

 来源：[OurJS.cn](http://www.ourjs.cn)  原文：[http://www.ourjs.cn/show.php?id=597](http://www.ourjs.cn/show.php?id=597)