为的GetList反应应该是一个数组,而不是一个对象或东西在别的restangular [英] Response for getList SHOULD be an array and not an object or something else in restangular

查看:328
本文介绍了为的GetList反应应该是一个数组,而不是一个对象或东西在别的restangular的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用下面的code在我angularJs控制器


  VAR baseAccount = Restangular.all('账户');
    $ scope.submit =功能(){
        baseAccount.getList()。然后(功能(账户){
            $ scope.datas =账户;
        });


我得到以下错误,
 作为的GetList反应应该是一个数组,而不是一个对象或者别的什么restangular

有没有什么解决办法吗?


解决方案

您正在呼叫的GetList。它期望从服务器的数据是一个数组(一旦它被解析成一个真正的JS对象)。你的反应是不是数组。

您需要修复的服务器端code与阵列响应或变更角code要求一个单一的资源,而不是他们的数组的:

  VAR baseAccount = Restangular.all('账户');
$ scope.submit =功能(){
    baseAccount.get()。然后(功能(账户){
        $ scope.data =账户; //只有一个帐户
    });
};

when i use the following code in my angularJs controller

var  baseAccount = Restangular.all('account');
    $scope.submit = function(){      
        baseAccount.getList().then(function(accounts) {
            $scope.datas = accounts ;
        });

i get the following error, Response for getList SHOULD be an array and not an object or something else in restangular

is there any solution ?

解决方案

You're calling getList. which expects the data from the server to be an array (once it's been parsed into a real JS object). Your response is not an array.

You need to fix the server side code to respond with an array or change the Angular code to request a single resource instead of an array of them:

var baseAccount = Restangular.all('account');
$scope.submit = function () {
    baseAccount.get().then(function (account) {
        $scope.data = account; // Only one account
    });
};

这篇关于为的GetList反应应该是一个数组,而不是一个对象或东西在别的restangular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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