如何从json对象中删除$ promise和$ resolved [英] How to remove $promise and $resolved from json object

查看:114
本文介绍了如何从json对象中删除$ promise和$ resolved的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在角度中使用$ resource来获取json对象,其结构定义如下

I'm using $resource in angular to get json object and its structure is defined below

[
    {
        "id": 0,
        "name": "Type1"
    },
    {
        "id": 1,
        "name": "Type 2"
    }
]

获取数据后.. console.log(jsonObject)给了我

after fetching the data .. console.log(jsonObject) gives me

[Resource, Resource, $promise: Object, $resolved: true]

如何删除$ promise& $从结果对象中解析?
我尝试了angular.fromJson(json),但我仍然看到这些对象仍然存在。

How can I remove $promise & $resolved from the resulting object ? I tried angular.fromJson(json) but still I see that these objects still exist.

推荐答案

我是寻找相同的答案,但此刻我只知道这个丑陋的黑客:

I'm looking for the same answer, but at this moment I know only this ugly hack:

写一个这样的功能:

function cleanResponse(resp) {
    return JSON.parse(angular.toJson(resp));
}

并在每个查询中调用它(丑陋,是的):

and call it in every single query (ugly, yep):

function getSmt() {
    Resource.get({}, function (data) {
        $scope.some = cleanResponse(data);
    }, function (responce) {
        //handle error
    })
}

如果有人教我如何正确地做,我会很高兴

I'll be happy if someone would teach me how to do it correctly

这篇关于如何从json对象中删除$ promise和$ resolved的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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