Answer the question
In order to leave comments, you need to log in
How to get values for each element in an array?
You need to get all the tags and their data:
tagsController.get = function(req, res, next) {
tags.getTags(0, -1, function(err, tags) {
if (err) {
return next(err);
}
var data = {
tags: tags,
title: '#'
};
res.render('tags', data);
});
};
getTags
and get the tags, as well as the values for each of them:Tags.getTags = function(start, stop, callback) {
db.getSetMembers('tags:id', function(err, tags) {
if (err) {
return callback(err);
}
// console.log(tags) = [ '1', '2', '3' ]
tags.forEach(function(tag) {
async.parallel({
id: function(next) {
db.getObjectField('tag:' + tag, 'id', next);
},
tagname: function(next) {
db.getObjectField('tag:' + tag, 'tagname', next);
},
tagslug: function(next) {
db.getObjectField('tag:' + tag, 'tagslug', next);
}
}, function (err, results) {
if (err) {
return callback(err);
}
callback(null, results);
});
});
});
};
"data.tags":[{"id":1,"tagname":"","tagslug":""},{"id":2,"tagname":"","tagslug":""},{"id":3,"tagname":"","tagslug":""}]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question