我在表单中有一个下拉列表,其值需要在单击“保存”按钮时传递给网格。我正在使用kendo ui和knockout js
我在视图模型中将其绑定为:
JS
this.blahList = ko.observableArray(["1", "1", "p3","c3ai"]);
this.blah = ko.observable();
this is my add function:
this.addBorrower = function() {
this.borrowers.push(new Borrower({ name: this.newName(), address: this.newAddress() , blah: this.newBlah()}));
};
HTML
<li>
blah :
<input data-bind="kendoDropDownList: { data: blahList, value: newBlah}" />
</li>
显示错误
ERROR
Uncaught Error: Unable to parse bindings.
Message: ReferenceError: newBlah is not defined;
Bindings value: kendoDropDownList: { data: blahList, value: newBlah}
Uncaught TypeError: Object #<AppViewModel> has no method 'newBlah'
有人可以帮助我吗?
答案 0 :(得分:4)
kendoDropDownList绑定试图将下拉列表中的值写入名为“newBlah”的属性,该属性应该在您的视图模型上,但不是。
将您的视图模型更改为
this.blahList = ko.observableArray(["1", "1", "p3","c3ai"]);
this.newBlah = ko.observable(); //this is where the value will be stored
换句话说,对于kendoDropDownList绑定,您分配给“data”和“value”的属性必须存在于视图模型上。在这种情况下,视图模型上必须存在“blahList”和“newBlah”。