gpt4 book ai didi

axios - 带有 Axios 和 Loopback 的 "where"过滤器中的变量

转载 作者:行者123 更新时间:2023-12-04 05:54:45 28 4
gpt4 key购买 nike

我在向 Loopback(v3) API 发出的 Axios 请求中使用变量时遇到了麻烦。

什么有效?如果我使用“REST 表示法”,它运行良好:

 getInfo() {
axios.get('http://myIp/api/tabs?filter[where][name]=' + this.name).then(response => {
this.tabs = response.data
})

什么还不行:

我无法将“REST 表示法”转换为我更喜欢在这里使用的“节点表示法”。

我已经尝试过的:

axios.get('http://myIp/api/tabs?filter={"where":{"name": this.name }}).then(response => {
this.tabs = response.data
})

我意识到在整个请求周围使用单引号,我无法进行变量插值。但是如果我使用双引号,我不知道如何转义用于“where”等保留字的双引号,...

在此上下文中使用变量的正确方法是什么?

最佳答案

尝试:

axios.get('http://myIp/api/tabs').then(response => {
this.tabs = response.data.filter(b => b.name === this.name)

它应该可以工作。主要技巧是 response.data.filter() 然后在 filter() 中提供您的过滤器逻辑。

关于axios - 带有 Axios 和 Loopback 的 "where"过滤器中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52946925/

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