用角与Parse.com REST API查询格式包括/极限/计数 [英] Parse.com REST API query format with Angular with include/limit/count

查看:105
本文介绍了用角与Parse.com REST API查询格式包括/极限/计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了几种不同的方法得到过滤后的数据从REST API,但是无法弄清楚查询正确的格式。这项工作对我来说:

I have tried a few different methods to get filtered data back from the REST API but cannot figure out the correct formatting for queries. This work for me:

var query = encodeURIComponent('where=' + '{"' + type + '":"' + subtype + '"}');

      $http.get('https://api.parse.com/1/classes/events?' + query,
             {headers:{
                'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,
                'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,
                'Content-Type' : 'application/json'
            }
          })
    },

但是,试图以包括其他参数如'有','限制'和'伯爵'我试过很多次迭代,但无济于事时。大多数queires返回一个糟糕的回应,但该查询返回一个空数组(这不是我想什么,但至少它返回的东西):

But when trying to include the additional parameters such as 'include', 'limit', and 'count' I have tried many iterations, but to no avail. Most queires returned a bad response, however this query returns an empty array (which isn't what I would like, but at least it returned something):

var query = encodeURIComponent('where=' + '{"' + type + '":"' + subtype + '", "limit":2}')

我还使用带有折角的$ HTTP对象,但即使采用相同的格式上面的查询,它返回一个错误响应params对象尝试。谁能给我正确的格式为这个呢?这一点,例如,似乎不工作:

I have also tried using a params object with Angular's $http object but even with the same formatting as the above query, it returns a bad response. Can anyone give me the correct formatting for this as well? This, for example, does not seem to work:

   $http.get('https://api.parse.com/1/classes/events',
                     {params: {"where" : encodeURIComponent('{"senses":"touch"}') }},
                     {headers:{
                        'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,
                        'X-Parse-REST-API-Key':PARSE_CREDENTIALS.REST_API_KEY,
                        'Content-Type' : 'application/json'
                    }
                  })

谢谢!

推荐答案

您是得太多这一点,因为很多与编码的问题相当普遍,并有被已经解决了利益。所以,你不需要做字符串格式化/编码, $ HTTP - 只需要使用对象

You are "overthinking" this since a lot of the problems with encoding are quite common and have the benefit of being already solved. So, you don't need to do string formatting/encoding with $http - just use objects.

此外,检查后 parse.com API 限制计数包含都是兄弟姐妹,其中 - 不是孩子

Also, after checking parse.com API, limit, count and include are siblings of where - not children.

所以,你需要做的是:

var whereQuery = {type: subtype};

$http.get('https://api.parse.com/1/classes/events',
   {
     headers: {
                'X-Parse-Application-Id': PARSE_CREDENTIALS.APP_ID,
                'X-Parse-REST-API-Key': PARSE_CREDENTIALS.REST_API_KEY,
                'Content-Type' : 'application/json'
              },
     params:  { 
                 where: whereQuery,
                 limit: 2,
                 // count: 1
                 // include: "something"
              }
   });

这篇关于用角与Parse.com REST API查询格式包括/极限/计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆