javascript - Issue with pushing data to array in KnockoutJS -


in html page there 3 inputs. using user inputs, wish update elements of page using knockoutjs. script have written:

$(document).ready(function(){      function task(data){         this.goal=ko.observable(data.goal);         this.type=ko.observable(data.type);         this.date=ko.observable(data.date);         console.log("data"+ " " + data.goal);      }        var myviewmodel=function(tasks){         var self=this;         self.tasks=ko.observablearray([{goal:"abc", type:"intermediate", date:"12/13/1122"}]);         self.newgoaltext=ko.observable("");         self.newtypetext=ko.observable("");         self.newdatetext=ko.observable("");           self.addtask=function(){             self.tasks.push(new task({goal:this.newgoaltext(),type:this.newtypetext(), date:this.newdatetext()}));              console.log(tasks);          self.newgoaltext("");         self.newtypetext("");         self.newdatetext("");       }//addtask function      }//viewmodel       ko.applybindings(new myviewmodel())  }); 

the console.log tells me values being obtained user expected. however, "push" method on tasks array seem have no effect @ all. please guide me.

if passing array task, have everytime, so, when initialize, have use [new task({...}), new task({...})]

your console.log(tasks); not correct. showing tasks variable, not self.tasks, i'm wondering want show, careful variable names , (none)varname vs this.varname vs self.varname or have headaches...

finally here are example working.

i hope you.

regards.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -