javascript - Recursive callbacks -
need little trying breadcrumb builder working - it's recursive fetch parent categories should return array of entries. not quite working , brain fried.... returns last entry.
var walk = function(c, done) { var results = []; category.findbyid(c).exec(function(err, cat) { if(cat) { results.push({ title: cat.title, id: cat.id}); if(cat.parent) { walk(cat.parent, function(err, res) { results = results.concat(res); }); } return done(null, results); } done(results); }); }; walk(product.categories[0].id, function(err, results) { // if (err) console.log (err); console.log(results); });
how node-fibers? try this.
good example link : mongo-model example
and method synchronize util written coffee-script
Comments
Post a Comment