我开始学习AngularJS $资源,并注意到$resource对象有一些附加到从服务器下载的数据的方法(参见下面的示例).如何删除这些方法并将对象转换为常规(数组)对象?
原文链接:https://www.f2er.com/angularjs/140281.html__proto__: Resource $delete: function (params,success,error) {$get: function (params,error) {$query: function (params,error) {$remove: function (params,error) {$save: function (params,error) {constructor: function Resource(value) {toJSON: function () {__proto__: Object
例如,我正在尝试使用$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.'); }); };
厂
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 } } }); }]);