我正在使用knockout.js开展一个项目,这个错误发生在firebug中:
Message: ReferenceError: Name is not defined;
Bindings value: text: Name
这是“Name”被定义为可观察数组
的地方 <div data-bind="foreach: favoriten">
<fieldset>
<span class="projektZeile"><strong data-bind="text:Name"></strong> </span>
<span class="projektZeile" data-bind="visible: IsFavorite()">
<a href="" data-bind="click: function(data, event) { $parent.makeNoFavorite(Name,data, event)}" ><img src="../../Content/Images/isFavorite.png"/></a>
</span>
<span class="projektZeile" data-bind="visible: !IsFavorite()">
<a href="" data-bind="click: function(data, event) { $parent.makeFavorite(Name,data, event)}"><img src="../../Content/Images/makeFavorite.png"/></a>
</span>
<span class="projektZeile"><a href="" class="button" data-bind="click: function(data, event) { $parent.showStart(Name,IsFavorite,data, event) }">STARTEN</a></span>
</fieldset>
</div>
这是我的可观察数组
self.favoriten = ko.observableArray([
{
Name: "Favorit1", IsFavorite: ko.observable(true)
}]);
接下来是,开始按钮不起作用:
self.showStart = function (projectName, isFavorite, data, event) {
alert(projectName());
masterViewModel.projectStartVM(new ProjectStartVM(projectName, isFavorite));
masterViewModel.startVM(null);
};
带有“projectName()”的警报甚至无效..
我做错了什么?
编辑: 这个小提琴显示我的问题非常好:http://jsfiddle.net/t3Z9x/