javascript - Save values into an array from a function which is called consecutively -


i have function called when file needed read in folder. in case since have 3 files in folder, called 3 times consecutively. need save files info array mapped_data2 that:

mapped_data2[0] = inner_data1 //first file info,  mapped_data2[1] = inner_data2 //second file info etc.  

however using code having first files information 3 times. bit confused global variables, if can point out problem, appreciate it.

here code:

var mapped_data = []; var mapped_data2 = [];                    function o(msg) {                          if (msg.data) {          var inner_data = [];          var lines = msg.data.split('\n'); //read lines of file          (var = 2; < lines.length; i++) {               if (lines[i].length > 0) {                   .. //do same data format here                   inner_data.push([son, vactual, voutput]);                   }            }       mapped_data = inner_data;         }       else {          if (msg.topic == "/somefolder/somefolder") {                   (var = 0; < msg.args.length; i++) {                   var filename = msg.args[i];                   aw.get(filename);                   }          }       } }  function de() { //where wanted use these files info     (var = 0; < 3; i++) {          mapped_data2[i] = { key: "group" + (i + 1), values: mapped_data };     }      var datam = mapped_data2;     var den = json.stringify(datam);     document.write(den); };  function init() {                   ..//create new client called aw server application , start it;                   ..//if connection established:                     aw.onmessage = o;                   aw.get("/somefolder/somefolder"); // request list of files in folder                                           }; //when html page being onload, call functions init() , de() 

var mapped_data2 = [];                     function o(msg) {      var mapped_data = []; // doesn't need global      if (msg.data) {          var inner_data = [];          ...                       mapped_data = inner_data;         } else {          ...      }       mapped_data2.push({ key: "group" + mapped_data2.length + 1, values: mapped_data };)      // more stuff in den() } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -