javascript - How to update value of an object from knockoutjs? -


i'm using knockoutjs bind data table, , want update object @ user click. here code

    var books = [{book:"harry potter",author:"j.k rowling"},{book:"5 point someone",author:"chetan bhagat"},{book:"i had love story",author:"ravinder singh"}];      var appviewmodel = function() {         this.firstname = ko.observable("amit");         this.books = ko.observablearray([]);         this.books(books);         this.updatebook = function() {             this.book("harry potter , prisoner of azkaban");         }     };     ko.applybindings(appviewmodel);                      

but error: "uncaught typeerror: string not function". how can fix ?

see: http://jsfiddle.net/jvqy8/8/

you need properties of each of book object observable well. use mapping plugin (that built-in) that:

this.books = ko.mapping.fromjs(books); 

also, it's bit misleading see this twice when each refers different object. common approach is:

this.updatebook = function(book) {     book.book("harry potter , prisoner of azkaban"); }; 

see fiddle


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -