gpt4 book ai didi

javascript - 环回中 REST 连接器查询中的重复键

转载 作者:行者123 更新时间:2023-11-30 15:30:33 25 4
gpt4 key购买 nike

我想问问您是否知道如何在环回 REST 连接器查询中复制参数。我有以下代码:

details: {
'template': {
'method': 'GET',
'debug': true,
'url': 'https://www.example.com/data',
'timeout': 10000,
'headers': {
'Authorization': 'Bearer {token}'
},
'query': {
q: 'PHOTOS'
q: 'DETAILS',
id: '{id}'
},
'options': {
'useQuerystring': true
},
'responsePath': '$'
},
'functions': {
'searchData': [
'token',
'id'
]
}
}

问题在于,loopback 似乎用最后一个参数覆盖了参数 q 的值,因为我只获得了最后一个参数的信息。

知道怎么解决吗?

先谢谢你。

最佳答案

您只需将它们作为数组传递:

  'query': {
q: ['PHOTOS', 'DETAILS'],
id: '{id}'
},

注意 options 键是 passedrequest这是 useQuerystring 的文档:

  • useQuerystring - If true, use querystring to stringify and parse querystrings, otherwise use qs (default: false). Set this option to true if you need arrays to be serialized as foo=bar&foo=baz instead of the default foo[0]=bar&foo[1]=baz.

因此,如果您删除它,您将以类似 ?q[0]=PHOTOS&q[1]=DETAILS 的内容结束。

您还可以在那里选择另一个选项:

  • qsStringifyOptions - object containing options to pass to the qs.stringify method. Alternatively pass options to the querystring.stringify method using this format {sep:';', eq:':', options:{}}. For example, to change the way arrays are converted to query strings using the qs module pass the arrayFormat option with one of indices|brackets|repeat

所以你实际上可以添加这个相同的东西:

  "options": {
"qsStringifyOptions": {
"arrayFormat": "repeat"
}
}

如果你只想有括号(像这样的 ?q[]=PHOTOS&q[]=DETAILS)你可以指定 brackets 选项:

  "options": {
"qsStringifyOptions": {
"arrayFormat": "brackets"
}
}

关于javascript - 环回中 REST 连接器查询中的重复键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42313383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com