-1

如何将带有部分和部分实例数据的课程对象作为单个 json 响应发送

Section.hasOne('course', db.models.courses, {reverse: 'section'});

Section_Instance.hasOne('course', db.models.courses, {reverse: 'section_instance'});
Section_Instance.hasOne('section', db.models.sections, {reverse: 'section_instance'});
4

1 回答 1

0

您应该查看 async.js 库。对于您的问题,请使用 async.parallel:

npm install --save async

var async = require("async");
async.parallel({
course: function (callback) {
// course query here
callback(null, results_from_coursequery); // null is error - you can also assign the error variable from query.
},
section: function (callback) {
// course query here
callback(null, results_from_sectionquery); // null is error - you can also assign the error variable from query.
}
},
function(err,results) {
if(err) {res.json(err);}
else {res.send(results);} // results is now an object similar to: {course: [object], section: [object]}
});
于 2015-12-04T06:00:01.810 回答