简体   繁体   English

Angular2 - 无法使用查询中的“where”条件获取REST API

[英]Angular2 - Unable to fetch using a 'where' condition in query to a REST API

I am working with Parse Server, and I am trying to fetch data using the REST API in my Angular2 application. 我正在使用Parse Server,我正在尝试使用Angular2应用程序中的REST API获取数据。

I am trying to fetch data according to a where condition, but I am not able to do so. 我试图根据where条件获取数据,但我无法这样做。

This is the code I am using: 这是我正在使用的代码:

  constructor(http) {
        var key = new URLSearchParams();
        this.http = http;
        this.disho = null;

        key.set('where', {"estTime":"5min"});
        this.http.get('https://parseapi.example.com/classes/Setto', { where : key }).subscribe(data => {
        this.disho = data.json().results;
        console.log(this.disho);
        });

      }

The above code ignore my where condition, and returns all the records. 上面的代码忽略了我的where条件,并返回所有记录。

However, the following code returns the right results when executed in terminal via cURL 但是,以下代码通过cURL在终端中执行时返回正确的结果

curl -X GET \
-H "X-Parse-Application-Id: someKey" \
-H "X-Parse-REST-API-Key: someKey" \
-G \
--data-urlencode 'where={"estTime":"5min"}' \
https://parseapi.example.com/classes/Setto

Change { where : key } to { search : key } { where : key }更改为{ search : key }

Should work! 应该管用!

I think that there is a typo in your code. 我认为您的代码中存在拼写错误。 Single quotes are missing. 单引号丢失。 You could try the following: 您可以尝试以下方法:

key.set('where', '{"estTime":"5min"}');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM