BiSheng.js 是纯粹的数据双向绑定库。
BiSheng.js 的名称源自活字印刷术的发明者“毕昇”。因为单向绑定犹如“刻版印刷”,双向绑定犹如“活字印刷”,故名 BiSheng.js。
下载 BiSheng.js
bower install bishengjs
引入 BiSheng.js
<script src="./bower_components/bishengjs/dist/bisheng.js"></script>
使用
// HTML 模板
var tpl = ’{{title}}’ // 数据对象 var data = { title: ‘foo’ } // 执行双向绑定 BiSheng.bind(data, tpl, function(content){ // 然后在回调函数中将绑定后的 DOM 元素插入文档中 $(‘div.container’).append(content) }); // 改变数据 data.title,对应的文档区域会更新 data.title = ‘bar’
代码的结构 按照职责来设计,见下表; 打包后的文件 在 dist/ 目录下; API 和文档 在 doc/ 目录下; 测试用例 在 test/ 目录下,基本覆盖了目前已实现的功能。