函数不返回值

时间:2018-06-14 07:51:40

标签: javascript node.js express sequelize.js

void hello(){
   char a,b;
}

函数const isName = req => { return user .find({ where: { name: req.body.name } }) .then(row => { return row == null ? true : false; }); }; 没有返回值。这个简单的代码isName()没有返回值,但我确信它正在运行。是什么原因?

2 个答案:

答案 0 :(得分:1)

查询是异步的,因此请确保等待结果并发送:

// I guess it's a route handler
const isName = async (req, res) => {
    const result = await user
        .find({ where: { name: req.body.name } })
        .then(row => row === null); // same as row === null ? true : false;

     res.send(result);
 };

答案 1 :(得分:0)

问题:

isName().then(isThere => { // <------- To get value you should handle like this
    if(isThere) {

    } else {

    }
})
  

所以你不能像isName()一样调用并得到预期的结果,诺言   应该处理以获得预期的结果

解决方案:

from xlwings import constants
validation_list = "linear_benefit,linear_cost,sigmoid_benefit,sigmoid_cost"
dv_type = constants.DVType.xlValidateList
dv_alertstyle = constants.DVAlertStyle.xlValidAlertStop
dv_operator = constants.FormatConditionOperator.xlEqual
rng.api.Validation.Add(dv_type, dv_alertstyle, dv_operator, validation_list)