JavaScript Array.push()在函数中不起作用

时间:2017-05-03 16:45:22

标签: javascript arrays push

当我将一个对象推入一个数组时,它可以在函数之外工作,但它又是空的!

    .get(function(req, res){
    //Mongoose Model
    var employeeModel = require('../models/employeeModel');
    var employeeList = new Array();
    employeeItems = req.project.involvedEmployee;
    employeeItems.forEach(function(entry) {
        var employeeId = entry.employeeId;
        employeeModel.findById(employeeId, function(err, employee){
            if(err){
            res.status(500).send(err);
            }
            else {
                employeeList.push(employee);
            }                        
        });                          
    });
    res.json(employeeList);
});

请告诉我我的问题是什么?

0 个答案:

没有答案