backbone-bind

0.2.0 • Public • Published

Backbone Binding

Build Status

Super simple 2way binding for Backbone views.

This plugin requires browserify, but feel free to open PR or issues if you want to use the plugin with something else.

Install

npm i -S backbone-bind

Usage

var binding  = require('backbone-bind');
var Backbone = require('backbone')
var model    = require('./model');
 
// bind typical input view with this.model
var View = Backbone.View.extend({
  tagName: 'input',
  bind: binding
  render: function() {
    this.bind('title');
    return this;
  }
});
 
var view = new View({
  model: model
});
 
$('body').append(view);

Options

You can use either bind(options) or bind(field, options), as you prefer.

options.$el

Default value: this.$el

jQuery element that you will bind.

options.field

Name of model property that you will bind.

options.attr

Default value: val

Represents input value. (checked, val, innerText, etc).

options.direction

Default value: <>

Represents binding direction (model <-> element). Only < and > symbols make sence, but model <-> element is better to understand.

options.events

Default value: keydown

List of bound events like change, keypress, keydown...

options.model

Default value: this.model

Backbone model that you will bind.

Licence

MIT

Readme

Keywords

Package Sidebar

Install

npm i backbone-bind

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • shuvalov-anton