我在我的视图模型中有这个可观察数组。使用foreach循环遍历一个observableArray
this.months = ko.observableArray(['Jan', 'Feb', 'Mar',...]);
如果我尝试每个月来显示,这样的 -
<!-- ko foreach: { data: months, as: 'month' } -->
<span data-bind="text: month"></span>
<!-- /ko -->
它抛出一个错误 -
Uncaught ReferenceError: Unable to process binding "text: function(){return month }"
Message: month is not defined
如果我试试这个,
<!-- ko foreach: months -->
<span data-bind="text: $data"></span>
<!-- /ko -->
它显示[对象对象]
我在做什么错?
谢谢。
不知道我做错了什么。我删除了与页面相关的所有敲除信息,并逐一添加回去。现在它起作用了。 – user471317
当我发生这种事时,我讨厌它。 –