これは単純なビューモデルです
var Cake=function(id,name,price,image)
{
this.id=ko.observable(id);
this.name=ko.observable(name);
this.price=ko.observable(price);
this.image=ko.observable(image);
};
var oldCakes=ko.observableArray(
[
new Cake('HSJ525','Name of the Cake',54.30,'http://placehold.it/160x100'),
new Cake('HSJ526','Other Cake',64.30,'http://placehold.it/160x100'),
new Cake('HSJ527','Another roquefort',84.30,'http://placehold.it/160x100'),
new Cake('HSJ528','AndTheLast',44.30,'http://placehold.it/160x100'),
])
var viewModel=function()
{
var self=this;
self.cakeBox=oldCakes;
}
window.view_model = new viewModel();
ko.applyBindings(window.view_model);
これはHtmlです
div.span12(data-bind='foreach:cakeBox')
div.row-fluid
div.span4
span(data-bind='text:$data.cakeBox().name()')
これがエラーです
Uncaught Error: Unable to parse bindings.
Message: TypeError: Object [object Object] has no method 'cakeBox';
Bindings value: text:$data.cakeBox().name()
どうして???