人,我有问题。 在此模型中,我进行了SQL查询:
module.exports.contribId = (request, callback) => {
connection.query(
'SELECT * FROM planilla_produccion_cantera WHERE id_planilla_produccion_cantera = ?',
request,
(err, result) => {
var objPlanilla = {
id: result[0].id_planilla_produccion_cantera,
periodo: result[0].periodo
};
console.log('MY OBJ EN DAO: ', objPlanilla);
callback(null, objPlanilla);
}
);
然后在控制器中,我想在地图中循环以获取数组的次数,并使查询选择模型中的数组次数:
module.exports.contribId =(请求,回调)=> { const todo = [];
const mapAsync = (arr, fn) => Promise.all(arr.map(fn));
mapAsync(request, id =>
contribModel.contribId(id, function(err, docs) {
todo.push(docs); //here I need to push each value
})
);
console.log(todo); //here I need to print all the values of mapsync
}
但是我无法完成阵列。你能帮我吗?
答案 0 :(得分:0)
尝试一下:
在模型中,只返回承诺。
B
在控制器中收集诺言并使用Promise.all api,然后解析数组或结果。
for (int i = 0, j = B.length - 1; i < A.length && j >= 0; ) {
if ( A[i] < B[j] ) {
i++;
} else if ( A[i] > B[j] ) {
j--;
}
return A[i];
}