繁体   English   中英

[ERR_INVALID_ARG_TYPE]:“id”参数必须是字符串类型。 接收类型对象

[英][ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object

通过这种方法,我得到了一个错误:

“id”参数必须是字符串类型。 接收类型对象

我不明白这里有什么问题。

const customers = await Customer.findAll({
  where: { id: _.map(users, 'customerId') }
});

if (customers) {
  const status = req.query.activation
    ? await Customer.findAll({ where: { activation: req.query.activation } })
    : customers;
  const search = req.query.search
    ? await Customer.findAll({
        name: { where: { [Op.like]: '%' + req.query.search + '%' } }
      })
    : status;

  return res.json({ search });
}
return response.sendBadRequest(res, 'customers empty!');

你的 id 是字符串,我认为我们不需要看到你的模型

但 _.map 产生一个数组而不是一个字符串

 map_.map(list, iteratee, [context]) Alias: collect
Produces a new array of values by mapping each value in list through a transformation function (iteratee). The iteratee is passed three arguments: the value, then the index (or key) of the iteration, and finally a reference to the entire list.

_.map([1, 2, 3], function(num){ return num * 3; });
=> [3, 6, 9]

Undeerscorejs 主页

所以你可以做的是使用 join 来获取你的字符串

const customers = await Customer.findAll({ where: {id: _.map(users, 'customerId' ).join('') }})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM