作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想问问您是否知道如何在环回 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
键是 passed至 request这是 useQuerystring
的文档:
useQuerystring
- If true, usequerystring
to stringify and parse querystrings, otherwise useqs
(default:false
). Set this option totrue
if you need arrays to be serialized asfoo=bar&foo=baz
instead of the defaultfoo[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 theqs
module pass thearrayFormat
option with one ofindices|brackets|repeat
所以你实际上可以添加这个相同的东西:
"options": {
"qsStringifyOptions": {
"arrayFormat": "repeat"
}
}
如果你只想有括号(像这样的 ?q[]=PHOTOS&q[]=DETAILS
)你可以指定 brackets
选项:
"options": {
"qsStringifyOptions": {
"arrayFormat": "brackets"
}
}
关于javascript - 环回中 REST 连接器查询中的重复键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42313383/
我是一名优秀的程序员,十分优秀!