-1
В настоящее время я работаю над этой функцией, а возвращаемое значение возвращается с undefined. Я не уверен, насколько я не понимаю, как работает javascript, или для того, чтобы заставить мой код работать с каким-то хитрым вуду.Функция возвращает значение undefined
var fs = require('fs');
var _ = require('underscore');
function eventValue(current, choice) {
\t var output = [];
\t if (current != null) {
\t \t var json;
\t \t fs.readFile('./json.json', 'utf8', function(err, data) {
\t \t \t if (err) {
\t \t \t \t throw err
\t \t \t }
\t \t \t json = JSON.parse(data);
\t \t \t // filter by ID
\t \t \t var filtered = _.filter(json, {
\t \t \t \t 'ID': current
\t \t \t });
\t \t \t //console.log(filtered);
\t \t \t // Get ID of Object
\t \t \t var ID = _.pluck(filtered, 'ID');
\t \t \t // Get Next value of object
\t \t \t var NEXT = _.pluck(filtered, 'next');
\t \t \t // get nested 'choice's 'next' value
\t \t \t var collect = _.pluck(_.filter(
\t \t \t \t _.flatten(
\t \t \t \t \t _.pluck(filtered, 'choice')), {
\t \t \t \t \t 'choice': choice
\t \t \t \t }), 'next');
\t \t \t var stringID = String(ID);
\t \t \t var stringNext = String(NEXT + collect);
\t \t \t output = [stringID, stringNext];
\t \t \t return output;
\t \t })
\t } else console.log("[[error]] please populate eventValue()");
};
var a = eventValue("001001A01B01");
console.log(a);