user1234
user1234

Reputation: 35

unable to parse bindings knockout js for drop down list

I have a drop down list in a form whose values need to be passed to a grid upon clicking save button. I am using kendo ui and knockout js

I am binding it in view model as :

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>

it shows an error

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' 

can someone help me?

Upvotes: 1

Views: 680

Answers (1)

Ryan Rahlf
Ryan Rahlf

Reputation: 1802

The kendoDropDownList binding is attempting to write the value from the dropdown to a property named "newBlah" which should be on your view model, but is not.

Change your view model to

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

In other words, for the kendoDropDownList binding, the properties you assign to "data" and "value" must exist on your view model. In this case, "blahList" and "newBlah" must exist on your view model.

Upvotes: 4

Related Questions