这是一个简单的视图模型
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()
为什么???