Warm tip: This article is reproduced from serverfault.com, please click

arrays-如何在JavaScript中获取URL时使用where条件?

(arrays - How to use where condition in fetch URL in javascript?)

发布于 2020-11-28 01:34:38

我在他们的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&params=id,name,lastname&where=[{%22attribute%22:%22level%22,%22value%22:{%22condition%22:%22=%22,%22value%22:4}}]

但是当我在fetch()其中使用此网址时不起作用

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中使用它?

Questioner
Bilal arshad
Viewed
11
Matthew Brooks 2020-11-28 10:15:52

仔细查看你传递的网址。你需要使用以下命令定义搜索字符串的开头?

fetch("https://....co/v400/path?mode=dashboard&params=id,name,lastname&where...")