javascript - Get value from function in loop nodejs -
i'm newbie in javascript , node js. want compare 2 data based on mysql value.
what want loop pair of data -> get
value db -> concat
pair of data , value -> endloop
here's code
routes/masterdata.js
var masterdata = require('../models/masterdata'); var outputfile = {} (var = 0; < datafile.length; i++) { if (datafile[i]['existing'] != null) { (var x = 0; x < datafile.length; x++) { var param = { tech_row: datafile[i]['existing'], tech_col: datafile[x]['new'] }; masterdata.comparedata(param, function(err, rows) { console.log(rows); outputfile.push({ value: rows }); }); } } } console.log(outputfile);
models/masterdata.js
var masterdata = { comparedata: function(param, callback) { return db.query('select value sod_matrix tech_name_row = ? , tech_name_col = ?', [param.tech_row, param.tech_col], callback); } }
my question how populate data function compare data array in loop?
var promise = require('bluebird'); var completed=[]; var masterdata = require('../models/masterdata'); var outputfile = []; //should array (var = 0; < datafile.length; i++) { if (datafile[i]['existing'] != null) { (var x = 0; x < datafile.length; x++) { var param = { tech_row: datafile[i]['existing'], tech_col: datafile[x]['new'] }; completed.push(new promise(resolve, reject){ masterdata.comparedata(param, function(err, rows) { if(err) { reject(err); } else { console.log(rows); outputfile.push(rows); //that;s pretty enough resolve(); } }); }); } } } promise.all(completed) .then((res) { console.log(outputfile); });
Comments
Post a Comment