【发布时间】:2015-02-26 12:54:42
【问题描述】:
我是这个淘汰赛 js 和 MVVM 架构的新手。无法在按钮单击事件上检索动态创建的文本框值。
代码:HTML
<div data-bind="foreach: cources">
<input type="text" data-bind="value: textValue"/>
<br>
</div>
<input type="button" data-bind="click:retrieve" value="Value"/>
代码:js
function CourseViewModel(){
textValue = ko.observable('');
}
var ViewModel= {
cources : ko.observableArray([new CourseViewModel()]),
retrieve: function()
{
var abc = $.parseJSON(ko.toJSON({ textValue: ViewModel.cources}));
alert(abc.textValue());
}
}
ko.applyBindings(ViewModel);
【问题讨论】:
-
你有什么错误吗?
-
Uncaught TypeError: object is not a function(index):35 ViewModel.retrieveknockout-min.js:59(匿名函数)
标签: jquery mvvm knockout.js