这里是 AngularJS 的新手,在让 $resource 工作时遇到了一些麻烦。我创建了一个工厂并使用后端需要的 $resource 对象进行硬编码,以便创建新的管道工。
但是,当我调用该函数时,它不会仅传递我输入的参数,而是以注册哈希的形式创建一种“某种”重复内容,如我的应用程序的 hte 后端所示(下面加粗)。它基本上是我的参数的完全副本。它从哪里来的???
create() 函数由管道工/new.html 模板中的按钮调用
<button data-ng-click="create()">create</button>
那个哈希是从哪里来的???
new.js
angular.module('ngappApp')
.controller('PlumbersNewCtrl', function ($scope, $window, $resource, Plumbers) {
$scope.create = function(){
var test1 = new Plumbers({
"business[email]": "superhero@super.com",
"business[password]": "123123",
"business[name]": "alice cullen",
"business[company]": "alice pty ltd",
"business[abn]": "12312312",
"business[contact_number]": "0421772800",
"business[address]": "118 glass street",
"business[suburb]": "essendon",
"business[postcode]": "3040",
"business[employees_number]": "8"
});
test1.$save();
};
});
angular.module('ngappApp')
.factory('Plumbers', function($resource){
return $resource('/businesses');
});
以及来自后端的响应:
在 2013-08-26 20:40:27 +1000 开始 POST "/businesses" for 127.0.0.1 ", "business[password]"=>"[FILTERED]", "business[name]"=>"alice cullen", "business[company]"=>"alice pty ltd", "business[abn]"= >"12312312", "business[contact_number]"=>"0421772800", "business[address]"=>"118 glass street", "business[suburb]"=>"essendon", "business[postcode]"= >“3040”,“企业[员工人数]”=>“8”,"registration"=>{"business[email]"=>"superhero@super.com", "business[password]"=>"[FILTERED]", "business[name]"=>"alice cullen", "商业[公司]"=>"alice pty ltd", "商业[abn]"=>"12312312", "商业[contact_number]"=>"0421772800", "商业[地址]"=>"玻璃街 118 号" , "business[suburb]"=>"essendon", "business[postcode]"=>"3040", "business[employees_number]"=>"8"}} 警告:无法验证 CSRF 令牌的真实性(0.1ms ) begin transaction (0.0ms) rollback transaction Completed 400 Bad Request in 6ms (Views: 0.1ms | ActiveRecord: 0.2ms)
编辑:
记录 test1 显示没有“额外”的正确参数
Resource {business[email]: "superhero@super.com", business[password]: "123123", business[name]: "alice cullen", business[company]: "alice pty ltd",
business[abn]: "12312312"
business[address]: "118 glass street"
business[company]: "alice pty ltd"
business[contact_number]: "0421772800"
business[email]: "superhero@super.com"
business[employees_number]: "8"
business[name]: "alice cullen"
business[password]: "123123"
business[postcode]: "3040"
business[suburb]: "essendon"