brix-bisheng數(shù)據(jù)雙向綁定庫
brix-bisheng 是純粹的數(shù)據(jù)雙向綁定庫。
安裝 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}}'
// 數(shù)據(jù)對象
var data = {
title: 'foo'
} // 執(zhí)行雙向綁定
var bs = BiSheng.bind(data, tpl, function(content){ // 然后在回調(diào)函數(shù)中將綁定后的 DOM 元素插入文檔中
$('div.container').append(content)
}); // 改變數(shù)據(jù) data.title,對應(yīng)的文檔區(qū)域會更新
bs.apply(function() {
data.title = 'bar'
})
})
方法 Methods
共計(jì) 6 個(gè)公開方法:
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 )
評論
圖片
表情
