brix-bisheng数据双向绑定库
brix-bisheng 是纯粹的数据双向绑定库。
安装 Install
$ bower install --save brix-bisheng'
用法 Usage
// 配置 Brix BiSheng 和依赖库require.config({
paths: {
jquery: 'bower_components/jquery/dist/jquery',
underscore: 'bower_components/underscore/underscore',
handlebars: 'bower_components/handlebars/handlebars'
'brix/bisheng': 'bower_components/brix-bisheng/dist/bisheng'
}
})// 加载 Brix BiShengrequire(['jquery', 'brix/bisheng'], function($, BiSheng){ // HTML 模板
var tpl = '{{title}}'
// 数据对象
var data = {
title: 'foo'
} // 执行双向绑定
var bs = BiSheng.bind(data, tpl, function(content){ // 然后在回调函数中将绑定后的 DOM 元素插入文档中
$('div.container').append(content)
}); // 改变数据 data.title,对应的文档区域会更新
bs.apply(function() {
data.title = 'bar'
})
})
方法 Methods
共计 6 个公开方法:
BiSheng.bind( data, tpl, callback )
BiSheng.unbind( data, tpl ) DEPRECATED
BiSheng.watch( data, handler( changes ) )
BiSheng.unwatch( data, handler )
BiSheng.apply( handler ) DEPRECATED
BiSheng.auto( bool )
评论
