Wrapper around Synapse for easy data binding between models and views.
GPL-3.0 License
.. image:: https://secure.travis-ci.org/passy/backbone.datalink.png?branch=master :alt: Travis CI build status :target: http://travis-ci.org/#!/passy/backbone.datalink
Simple wrapper around Synapse to keep data between your Backbone models and views in sync.
Synapse <http://bruth.github.com/synapse/docs/>
_ must be installed and
configured with both the jQuery and Backbone Model hook.
The library itself can be installed via the volo <http://volojs.org/>
_
package manager::
volo add passy/backbone.datalink
Alternatively, you can grab the latest version here:
Uncompressed <https://raw.github.com/passy/backbone.datalink/master/dist/backbone.datalink.js>
_Uglified <https://raw.github.com/passy/backbone.datalink/master/dist/backbone.datalink.min.js>
_Backbone.DataLink supports the UMD <https://github.com/umdjs/umd>
_ and can be
loaded in CommonJS environments, via AMD and as traditional browser script.
::
require(['synapse', 'synapse/jquery', 'synapse/backbone-model', 'datalink'],
function (Synapse, JQueryHook, BackboneModelHook, DataLink) {
Synapse.hooks = [Synapse, JQueryHook, BackboneModelHook];
}
)
To sync the elements title and description of your model with the corresponding input fields in your rendered view, add this after your rendering is done::
datalink.linkView(this, ['title', 'description'])
Your template may look like this::
<input data-bind=title>
<textarea data-bind=description>
To override the default settings, provide a hash as third parameter::
datalink.linkView(this, ['title', 'description'], {prefill: false})
To override certain settings for specific elements, provide a fourth parameter::
datalink.linkView(this, ['title', 'description'], {prefill: true}, {
'title': {attribute: "name"},
'description': {prefill: false}
})
bind
, default syncWith
attribute
, default data-bind
ignoreEmpty
, default false
prefill
, default true
triggerOnBind
, default false
There are some projects with similar goals:
Backbone.ModelBinder <https://github.com/theironcook/Backbone.ModelBinder>
_backbone.modelbinding <https://github.com/derickbailey/backbone.modelbinding>
_Dual licensed under the MIT or GPL Version 3 licenses.