javascript - For Loop refusing to Loop; Works Perfectly Fine if Run Manually -
alright, so, simple enough question. i'm sure has simple , stupid not doing right. i'm building app program exercise routine can keep track of every week (and learn app development using cordova). within code, each time come exersetup screen want read saved exercise file, parse array of objects, convert objects exercise objects, display them on screen. have loop supposed check each element of array process information, display, repeat until has done each element in array. works fine first item, stops. if manually run loop multiple times, functions perfectly. not listed code function addrow(), adds row of formatted dropdown selectors input, increments rownum keep track of row operating on. guys can offer appreciated. if need submit more information happy so. here's loop in question:
edit: fixed things suggestions in comments below. code still functions same. works fine on first run through loop, stops. if continue run loop manually (declaring on , on again in console) works fine, not, reason, run "for" loop. i've included rest of function loop nested in, in case helps.
function readrout() { console.log("reading routine..."); document.addeventlistener('deviceready', getfile, false); function getfile() { window.resolvelocalfilesystemurl(cordova.file.datadirectory, function(dir) { console.log("got main dir",dir); dir.getfile("exerciseroutine.txt", {create:true}, function(file) { console.log("got file", file); exerlog = file; console.log(exerlog); }); }); document.addeventlistener('deviceready', logout, false); } function logout() { settimeout(readlog, 50); } function readlog() { exerlog.file(function(file) { var reader = new filereader(); reader.onloadend = function(e) { console.log(this.result); exerroutine = json.parse(this.result); //console.log(exerroutine); //console.log(exerroutine[0]); var looper = exerroutine.length + 1; (var i=0; i<looper; i++) { console.log("loop count is: " + i); console.log(looper); exerroutine[i] = new exercise(exerroutine[i].type, exerroutine[i].name, exerroutine[i].sets, exerroutine[i].reps, exerroutine[i].pace); console.log(exerroutine[i]); console.log(exerroutine[i].description()); console.log(exerroutine[i].type); console.log(exerroutine[i].name); console.log(exerroutine[i].sets); console.log(exerroutine[i].reps); console.log(exerroutine[i].pace); addrow(); settimeout(fillexer, 50); console.log(exerroutine); } console.log(looper); }; reader.readastext(file); }, fail); } function fillexer() { var typerow = "typesel" + rownum; console.log(typerow); console.log(document.getelementbyid(typerow)); var namerow = "namesel" + rownum; var setsrow = "setssel" + rownum; var repsrow = "repssel" + rownum; var pacerow = "pacesel" + rownum; filltype(typerow); settimeout(fillname, 10, namerow); fillsets(setsrow); fillreps(repsrow); fillpace(pacerow); } function filltype(typek) { (var k=0; k<document.getelementbyid(typek).options.length; k++) { //console.log(document.getelementbyid(typek).options.length); console.log(exerroutine[rownum-1].type); if(document.getelementbyid(typek).options[k].value == exerroutine[rownum-1].type) { document.getelementbyid(typek).selectedindex = k; //console.log(document.getelementbyid(typei).selectedindex); var quer = "#" + typek; //console.log(query); var typeinput = document.queryselector(quer); //console.log(typeinput); typeselect(typeinput); return; } } } function fillname(namek) { (var k=0; k<document.getelementbyid(namek).options.length; k++) { //console.log(document.getelementbyid(namek).options.length); console.log(exerroutine[rownum-1].name); if(document.getelementbyid(namek).options[k].value === exerroutine[rownum-1].name) { document.getelementbyid(namek).selectedindex = k; //console.log(document.getelementbyid(namei).selectedindex); return; } } } function fillsets(setsk) { (var k=0; k<document.getelementbyid(setsk).options.length; k++) { console.log(exerroutine[rownum-1].sets); if(document.getelementbyid(setsk).options[k].value === exerroutine[rownum-1].sets) { document.getelementbyid(setsk).selectedindex = k; //console.log(document.getelementbyid(setsk).selectedindex); return; } } } function fillreps(repsk) { (var k=0; k<document.getelementbyid(repsk).options.length; k++) { console.log(exerroutine[rownum-1].reps); if(document.getelementbyid(repsk).options[k].value === exerroutine[rownum-1].reps) { document.getelementbyid(repsk).selectedindex = k; //console.log(document.getelementbyid(repsi).selectedindex); return; } } } function fillpace(pacek) { (var k=0; k<document.getelementbyid(pacek).options.length; k++) { console.log(exerroutine[rownum-1].pace); if(document.getelementbyid(pacek).options[k].value === exerroutine[rownum-1].pace) { document.getelementbyid(pacek).selectedindex = k; //console.log(document.getelementbyid(pacek).selectedindex); return; } } } }
Comments
Post a Comment