I'm trying to make a simple viewmodel to display a list of objects with Knockback. The View Model is rather simple, looking like this:
var objectives_collection = new ObjectiveCollection();
objectives_collection.fetch();
var view_model = kb.ViewModel.extend({
objectives: kb.CollectionObservable(objectives_collection),
constructor: function() {
_this = this;
kb.ViewModel.prototype.constructor.call(this, model = new Objective(), {});
console.log(this.objectives);
return this;
},
addObjective : function() {
var objective_model = new Objective({name: "New Objective", descriptor: 'Add description here'});
this.objectives.add(objective_model);
objective_model.save();
console.log(objectives);
},
edit: function() {
console.log('Edit');
},
remove: function(objective) {
self.objectives.remove(objective);
}
});
Right now though, the first line of the view model (kb.CollectionObservable(objectives_collection)) is giving me grief. It's calling Underscore.js' bind function and trying to set up the onCollectionChange listener, but Knockback's line here is trying to bind an undefined function:
this.__kb._onCollectionChange = _.bind(this._onCollectionChange, this);
where this._onCollectionChange is apparently undefined. I'm not really sure what to make of this; what am I doing wrong here?