如何在没有方法的情况下将Angular $ resource对象转换为常规对象

Jas*_* O. 7 resources angularjs

我开始学习AngularJS $资源,并注意到$ resource对象有一些附加到从服务器下载的数据的方法(参见下面的示例).如何删除这些方法并将对象转换为常规(数组)对象?

__proto__: Resource $delete: function (params, success, error) {$get: function (params, success, error) {$query: function (params, success, error) {$remove: function (params, success, error) {$save: function (params, success, error) {constructor: function Resource(value) {toJSON: function () {__proto__: Object
Run Code Online (Sandbox Code Playgroud)

例如,我正在尝试使用$ resource.save发送包含一些键值数据的POST请求,但是数组中的这些" proto "项在某种程度上导致数据在传递给$ .param时变为"未定义"(数据) )在工厂里.我可以轻松地使用$ http做同样的事情,但想学习$ resource.谢谢!

控制器内部

 $scope.ok = function () {
        $scope.entry = new calEntry();  
        $scope.entry.data = data    // data is $resource object including _proto_ items
        $scope.entry.$save( function(){
            toaster.pop('success','Message','Update successfully completed.');
        });
    };
Run Code Online (Sandbox Code Playgroud)

myApp.factory("calEntry",['$resource','$filter', function($resource, $filter) {

    return $resource("/griddata/", {}, {
        save: {
            method: 'POST',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
            transformRequest: function(data, headersGetter) {
                return $.param(data);      // data is undefined when it reaches here
            }
        }
    });
}]);
Run Code Online (Sandbox Code Playgroud)

Pet*_*ell 10

尝试使用toJSON函数,它将获取数据并删除额外的属性.