-1

Here's my current code:

Model.containing(req.user.location, function(err, models) {
  if (err) throw err;
  res.render('models/index', {title: 'Models', models: models});
});

I get a list of models that contain the user's location. It works great. Now I want to get all of those previous models and one extra. I could retrieve this extra model with something like:

Model.find().where('name').equals('desired name').exec(function(err, models) {
 //got my models!
});

Could I combine them to do something like this?

Model.containing(req.user.location, function(err, models) {
  if (err) throw err;
  Model.find().where('name').equals('desired name').exec(function(err, newModels) {
    var allModels = models + newModels;
    res.render('models/index', {title: 'Models', models: allModels});
  });
});

Thanks!

4

1 回答 1

2

几乎,但是因为modelsnewModels是数组,您需要调用concat来合并它们而不是使用+

var allModels = models.concat(newModels);
于 2012-08-23T04:17:48.017 回答