本文介绍了在Restangular发送GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用在我的项目和前面code行之有效检索阵列对象:

I'm using Restangular in my project and earlier this code worked well for retrieving array of objects:

var params = {name: "Stack", surname: "Overflow"}
var service = Restangular.all('users')
service.getList(params)

从服务器响应只是对象的数组:

Response from server was just an array of objects:

[
 {...},
 {...}
]

但现在我添加分页,我的回答现在包含不是一个数组,而是一个对象,包括数组:

But now I added pagination, and my response now contains not an array, but an object which includes array:

{
   totalCount: 500,
   data: [
     {...},
     {...}
   ]
}

此外,我改变了 service.getList(PARAMS) service.get(PARAMS)(因为的GetList 预计仅数组)。

Also I changed service.getList(params) to service.get(params) (because getList expects only arrays).

和在此之后改变了我的GET参数不是字符串化,即我在这样的调试器要求见:

And after this changes my GET parameters are not stringified, i.e. I see in debugger request like this:

用户/ [对象%20Object]

但早期(使用的GetList 方法时),它的工作如我所料:

but earlier (when using getList method) it worked as I expected:

用户名=堆栈和放大器;?姓=溢

这里有什么问题吗?

推荐答案

我可以用这个来解决这个问题:

I was able to solve it using this:

var params = {name: "Stack", surname: "Overflow"}
var service = Restangular.all('users')
service.customGET("", params) // first parameter is required, so just provide empty string

这篇关于在Restangular发送GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 03:14