Reputation: 11
I am new to both knockout and using jsfiddle. Please let me know why this sample code does not run on jsfiddle.
Upvotes: 1
Views: 897
Reputation: 134581
You don't have valid javascript code so knockout wasn't able to do its magic. Also you were missing some critical things that makes it work.
Since you are binding to the name
property, it must be set as an observable
if you want to be able to see the changes.
name: ko.observable("knockout"),
Being an observable, you have to "call" it with your new value to change it. What you had in your changeName()
function was just not a valid statement (you were in the body of the function, not the object literal).
changeName: function () {
this.name("jsfiddle");
}
With those changes in place, it should work now.
Upvotes: 1