【发布时间】:2017-09-22 20:02:42
【问题描述】:
在我的 Angular 应用程序中,我通过 API 调用返回结果,并允许用户通过一系列复选框选择过滤这些结果。 Right now I'm running into an issue where, while results are returned as expected when one value is sent for a certain filter, when multiple values are selected (like filtering by more than one zipcode, for instance) I get zero results printed to风景。没有错误,只是没有结果。
在摸索了一会儿之后,使用 Chrome devtools 网络选项卡,我终于确定问题在于,而不是在有效负载中将每个项目用引号括起来 - 像这样:“90001”,“90002”,正在发送什么这是:“90001, 90002”。换句话说,引号被包裹起来,就好像它是一个值,而不是两个。
这是代码,我在其中使用“连接”将选定的值放在一起:
this.sendZipcode.emit(this.zipcodeFilters.text = arr.length === 0 ? undefined : arr.join(','));
我不确定如何调整这个“join”的构造方式,或者找到其他解决方案而不是“join”,以便将每个项目用引号括起来,而不是像一个长字符串一样包装。
仅供参考,这是我在选择两个邮政编码后在 Chrome devtools 的网络选项卡中看到的。正如我所解释的,它被包装成一个字符串,而不是两个值:
addresses.zipCode: {$in: ["90001, 90002"]}
【问题讨论】:
标签: javascript mongodb angular mongoose