1
我是node.js的新手。我需要在jqgrid中显示Name,但我只将一个文档的ID存储到另一个文档中。将新字段和值推送到node.js中的json数组对象
例
我有2个文件,如学生教师和学生的标记文件。我必须在jqgrid中显示标记详细信息。在标记文件中,我存储了学生ID而不是姓名。如何获取名称并向jqgrid发送新对象?
我的代码如下:
exports.getAllstudentsmark = function(req, callback)
{
studentsmarks.find(function(error, studentsmarks_collection) {
if(error) callback(error)
else {
studentsmarks_collection.toArray(function(error, results) {
if(error) callback(error)
else {
newresult = results;
for(i=0;i<results.length;i++)
{
newresult[i]['studentname'] = getStudentName(results[i].studentid);
}
console.log(newresult);
callback(null, newresult)}
});
}
});
}
var getstudentObjectId = function(id)
{
return student.db.bson_serializer.ObjectID.createFromHexString(id);
}
var getStudentName = function(id)
{
student.findOne({_id: getstudentObjectId (id)}, function(e, o){
console.log(o.name);
return o.name;
});
}
newresult [I] [ 'studentname']总是越来越不确定。但是如果我登录到getStudentName函数,我可以得到getStudentName函数的答案。
我的回调函数只能解决这个问题。如何解决并以简单的方式获得我的结果。请帮助任何人。
它越来越错误一样的ReferenceError:无效在作业中左手边 –
@VinothKumar我编辑了我的答案来解决这个问题 –