如何在fetch URL in javascript中使用where条件?
How to use where condition in fetch URL in javascript?
我在他们的 sdk 中使用第三方 api 他们已经提供了根据这样的条件获取数据的选项
Ordering.users.all({
mode: 'dashboard',
params: 'id,name,lastname',
where: [
{
attribute: 'level',
value: {
condition: '=',
value: 4,
}
}
]
},function (res) {
if (!res.error) {
$scope.drivers_filter = res.result
} else MyAlert.show(res.result)
})
在控制台中是这样的
Request URL: https://apiv4.ordering.co/v400/es-419-1/devyv4/users?mode=dashboard¶ms=id,name,lastname&where=[{%22attribute%22:%22level%22,%22value%22:{%22condition%22:%22=%22,%22value%22:4}}]
但是当我在 fetch()
中使用这个 url 时它不起作用
fetch("https://apiv4.ordering.co/v400/en/devyv4/users&where[{%22attribute%22:%22level%22,%22value%22:{%22condition%22:%22=%22,%22value%22:4}}]", {
method: "GET",
headers: {
"x-api-key": ""
}
}).then(r => r.json().then(data => (alert(JSON.stringify(data.result)))))
如何在 url 中使用它?
你需要一个 ?
在用户启动 searchParams 之后,atm 你有一个 &
不确定你是否遗漏了 URL 的一部分或什么。
仔细看看你路过的URL。您需要使用 ?
定义搜索字符串的开头
fetch("https://....co/v400/path?mode=dashboard¶ms=id,name,lastname&where...")
我在他们的 sdk 中使用第三方 api 他们已经提供了根据这样的条件获取数据的选项
Ordering.users.all({
mode: 'dashboard',
params: 'id,name,lastname',
where: [
{
attribute: 'level',
value: {
condition: '=',
value: 4,
}
}
]
},function (res) {
if (!res.error) {
$scope.drivers_filter = res.result
} else MyAlert.show(res.result)
})
在控制台中是这样的
Request URL: https://apiv4.ordering.co/v400/es-419-1/devyv4/users?mode=dashboard¶ms=id,name,lastname&where=[{%22attribute%22:%22level%22,%22value%22:{%22condition%22:%22=%22,%22value%22:4}}]
但是当我在 fetch()
中使用这个 url 时它不起作用
fetch("https://apiv4.ordering.co/v400/en/devyv4/users&where[{%22attribute%22:%22level%22,%22value%22:{%22condition%22:%22=%22,%22value%22:4}}]", {
method: "GET",
headers: {
"x-api-key": ""
}
}).then(r => r.json().then(data => (alert(JSON.stringify(data.result)))))
如何在 url 中使用它?
你需要一个 ?
在用户启动 searchParams 之后,atm 你有一个 &
不确定你是否遗漏了 URL 的一部分或什么。
仔细看看你路过的URL。您需要使用 ?
fetch("https://....co/v400/path?mode=dashboard¶ms=id,name,lastname&where...")