I have to enter the URL twice to see the data. What happened?
1.array keep data form fucntion createTree() for t.addNode(), output t.getNode() to display
var Tree = function() {
this.node = [];
}
Tree.prototype.addNode = function(value) {
this.node.push(value);
}
Tree.prototype.getNode = function() {
return this.node;
}
Tree.prototype.reset = function() {
this.node = [];
}
calling array var t = new Tree();
2.craete tree
function createTree(root, level = 0) {
if (level < 6) {
async.waterfall([
function(cb) {
Member.find({ sponsor: root }, function(err, member) {
return cb(null, member);
});
},
function(member, cb) {
if (member.length < 1) ? return 0 : return cb(null, member);
}
], function(err, data) {
if (!err) {
level += 1;
data.map(function(item) {
t.addNode(item);
createTree(item._id, level);
});
}
});
}
}
3.url params in express
exports.getReferralTable = function(req, res) {
async.waterfall([
function(cb) {
t.reset();
createTree(req.params._id);
return cb(null);
},
function(cb) {
return cb(null, t.getNode());
},
], function(err, data) {
if (err) {
res.json(err);
} else {
res.json(data);
}
});
}
how fix this problem
via CPTN3M0
No comments:
Post a Comment