简体   繁体   English

如何将多个值传递给一个参数

[英]How to pass multiple values to one parameter

Currently i have done code to accept one category_id in the param and return output base on category_id.目前我已经完成了在参数中接受一个 category_id 并根据 category_id 返回输出的代码。

if ('category' in params) {
        assert.number(params.category, 'params.category')

        const { category: category_id } = params
        query = query.where('category.id', category_id)
      }

Now i want to pass multiple values to category_id and return result for all category_id's.现在我想将多个值传递给 category_id 并返回所有 category_id 的结果。

I will pass like this, category_id=1,2,3我会这样通过, category_id=1,2,3

Can someone helps me to fix this?有人可以帮我解决这个问题吗?

http://knexjs.org/#Builder-whereIn

query.whereIn('category.id', [1, 2, 3]);

Improve Ростислав Борніцький answer little bit,改进Ростислав Борніцький的回答一点点,

if ('category' in params) {
        assert.array(params.category, 'params.category')

        const { category: category_id } = params
        query = query.whereIn('category.id', category_id)
      }

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

相关问题 为Web表单中的一个参数传递多个值 - Pass multiple values for one parameter in a web form React.js将多个json值传递给一个子参数 - React.js pass multiple json values to one child parameter 如何在Django中传递参数值? - How to pass parameter values in Django? 在JavaScript中的多个参数函数中传递一个参数 - Pass one parameter in multiple arguments function in javascript 如何将多个参数传递给函数 - How to pass multiple parameter to a function 如何使用 JS 将两个值 (lat lng) 传递给 GET 请求的一个参数键? - How can I pass two values (lat lng) to one parameter key of GET request using JS? 如何使用 http 客户端在 angular 9+ 中将多个值传递给 GET API 中的参数 - How to pass multiple values to a parameter in a GET API in angular 9+ using http client 在 postman 测试中,当输入参数可以为空时,如何使用多个值之一断言响应值? - In postman tests, how can i assert the response values with one of multiple values when the input parameter can be empty? 如何将参数传递给自治函数并获取值? - How to pass the parameter to autonomous function and get the values? 如何将var值传递给javascript中的参数? - How to pass var values to a parameter in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM