【问题标题】:How to use where condition in fetch URL in javascript?如何在javascript中获取URL中使用where条件?
【发布时间】:2021-03-10 17:22:17
【问题描述】:

我在他们的 sdk 中使用了第三方 api,他们提供了基于这样的 where 条件获取数据的选项

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

【问题讨论】:

    标签: javascript arrays json angularjs


    【解决方案1】:

    在用户启动 searchParams 后你需要一个?,atm 你有一个& 不确定你是否错过了部分 URL 或什么。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-26
        • 1970-01-01
        • 2019-06-03
        • 1970-01-01
        • 1970-01-01
        • 2020-10-28
        相关资源
        最近更新 更多