knockout.js - Loading data from observableArray one-by-one clicking button -
i came across nice sample code knockout.js , learning. curious understand code flow. when try read code stuck understand specific area. here jsfiddle link can see full code http://jsfiddle.net/rustam/ssbzs/
//this 2 area clear this.currentquestion = ko.computed(function(){ return self.questions()[self.questionindex()]; }); this.nextquestion = function(){ var questionindex = self.questionindex(); if(self.questions().length - 1 > questionindex){ self.questionindex(questionindex + 1); } }; this.prevquestion = function(){ var questionindex = self.questionindex(); if(questionindex > 0){ self.questionindex(questionindex - 1); } };
when clicking next or previous button 2 function getting called prevquestion & nextquestion
2 routine questionindex
value getting changed , accordingly question , answer set changing.
my problem there no link between questions , questionindex
know when questionindex
getting change how question set changing ?
please me understand how new or old question set loaded when click on next or prev button.
thanks
questions not changing, current question getting changed because it's computed value.
this.currentquestion = ko.computed(function(){ return self.questions()[self.questionindex()]; });
and depends on questionindex
, every time questionindex
changed currentquestion
re-calculated.
Comments
Post a Comment