Koba

Documentation

Live exemples

Learn the easy way with many live exemples.

API

koba.ViewModel

The object ViewModel is the glue between Backbone and Knockout. You can use it in your view implementation instead of koba.View (for exemple, if you use a framework like ChaplinJS or MarionetteJS).

See exemple Working directly with koba.ViewModel and Backbone.View.

constructor

Initialize a new ViewModel from data.

var myData = {}; // define your data
var myViewModel = new koba.ViewModel(myData);
destroy

Destroy the ViewModel (remove data-binding).

myViewModel.destroy();

koba.View

koba.View manages a koba.ViewModel to bind data to DOM with Knockout. The ViewModel livecycle is managed by the View to prevent memory leak.

koba.View extends directly from Backbone.View.

See many exemples.

extend

Extends koba.View (see http://backbonejs.org/#View-extend).

var MyView = koba.View.extend({
    // define your view (events, render function...)
});
constructor

With data:

var myData = {}; // define your data
var myView = new MyView({data: myData}); // Create view with data

Without data:

var myView = new MyView(); // Create view without data
render

Render the view (see http://backbonejs.org/#View-render).

The HTML produced can use declarative bindings from Knockout (see http://knockoutjs.com/documentation/introduction.html).

myView.render();
bindData

Bind data with existing data in view:

myView.bindData();

Bind data with new data (data in view is changed by the new data):

var myData = {}; // define your data
myView.bindData(myData);
remove

Remove the view (see http://backbonejs.org/#View-remove), remove data-binding and remove data in view.

myView.remove();
unbindData

Remove data-binding. Data in view is not removed.

myView.unbindData();
Fork me on GitHub