小编mas*_* cm的帖子

如何在创建新记录时在风帆中使用"等待"

我想用"等待"

根据sails文档,我的行为如下:https:
//sailsjs.com/documentation/reference/waterline-orm/models/create

create: function (req, res, next) {

var new_place = await Place.create({...}, function place_created(err, XX){

  if(err && err.invalidAttributes) {
    return res.json({'status':false, 'errors':err.Errors});
  } 
}).fetch();
if(new_place){
  console.log(new_place);
  res.json({'status':true,'result':new_place});
 }
},  
Run Code Online (Sandbox Code Playgroud)

但是我得到以下错误:

var new_place = await Place.create({...}, function place_created(err, XX){
                ^^^^^
SyntaxError: await is only valid in async function  
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能解决这个问题.

node.js sails.js

2
推荐指数
1
解决办法
3375
查看次数

标签 统计

node.js ×1

sails.js ×1