Class: kb.ViewModel
Defined in: | src/core/view-model.coffee |
Overview
Base class for ViewModels for Models.
Examples:
How to create a ViewModel with first_name and last_name observables.
var view_model = kb.viewModel(new Backbone.Model({first_name: "Planet", last_name: "Earth"}));
Bulk kb.Observable create using 'key' Object to customize the kb.Observable created per attribute.
var ContactViewModel = function(model) {
this.loading_message = new kb.LocalizedStringLocalizer(new LocalizedString('loading'));
this._auto = kb.viewModel(model, {
keys: {
name: { key: 'name', 'default': this.loading_message },
number: { key: 'number', 'default': this.loading_message },
date: { key: 'date', 'default': this.loading_message, localizer: kb.ShortDateLocalizer }
}
}, this);
return this;
};
Creating ko.Observables on a target ViewModel
var view_model = {};
kb.viewModel(model, ['name', 'date'], view_model); // observables are added to view_model
Instance Method Summary
- # (void) destroy() Required clean up function to break cycles, release view models, etc.
- # (void) shareOptions() Get the options for a new view model that can be used for sharing view models.
- # (void) createObservables(model, keys) create observables manually
Constructor Details
#
(ko.observable)
constructor(model, options = {}, view_model)
Used to create a new kb.ViewModel.
Instance Method Details
#
(void)
destroy()
Required clean up function to break cycles, release view models, etc. Can be called directly, via kb.release(object) or as a consequence of ko.releaseNode(element).
Get the options for a new view model that can be used for sharing view models.
#
(void)
createObservables(model, keys)
create observables manually