dies ist mein Codenode.js koa nicht Wert an den Client in einem Asynchron-Funktion gesendet, aber außerhalb
-api.js-
const products=require('../pro');
module.exports ={
'POST /api/create':async(ctx,next)=>{
ctx.response.type = 'application/json';
async function aaa(){
var data=products();
return data;
}
aaa().then(v=>{
ctx.response.body=v;//the client show status 400
console.log(v);//here is my json from products(),and it is correct
})
ctx.response.body={a:111};// the client show it correctly
}
}
das Problem ist die erste ctx.response .body es nicht funktionieren kann, aber die andere Arbeit gut,
-pro.js-
const model = require('./model/model');
var add=function() {
return new Promise(resolve =>{
model.find({age:18}).lean().exec(function (err, res) {
if(err){
}
if(res){
var result= JSON.stringify(res) ;
resolve(result);
}
});
})
}
module.exports = add;
ich denke pro.js richtig ist, ist es nicht der Schlüssel o f mein Problem, also ..who kann mir helfen ..
oh hilft !!!! Es klappt !! ich danke dir sehr . Dieses Problem hat mich heute verwirrt! sooooooooo aufgeregt –