1

我有一个表单中的下拉列表,其值需要在单击保存按钮时传递给网格。我正在使用剑道 ui 和淘汰赛 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>

它显示一个错误

错误

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' 

有人能帮我吗?

4

1 回答 1

4

kendoDropDownList 绑定正在尝试将下拉列表中的值写入名为“newBlah”的属性,该属性应该在您的视图模型上,但不是。

将您的视图模型更改为

this.blahList = ko.observableArray(["1", "1", "p3","c3ai"]);
this.newBlah = ko.observable(); //this is where the value will be stored 

换句话说,对于 kendoDropDownList 绑定,您分配给“数据”和“值”的属性必须存在于您的视图模型中。在这种情况下,“blahList”和“newBlah”必须存在于您的视图模型中。

于 2013-06-12T13:01:54.483 回答