我有一个表格,其中添加了动态字段。
$scope.choices = [{id: 'choice1'}];
$scope.removeChoice = function(z)
{
var lastItem = $scope.choices.length-1;
$scope.choices.splice(z,1);
};
$scope.addNewChoice = function()
{
var newItemNo = $scope.choices.length+1;
$scope.choices.push({'id':'choice'+newItemNo});
};
调用insert函数时,值会正确插入控制器文件中。 inser功能如下。
$scope.insert = function()
{
$scope.checklist_name = $scope.values.checklist_name;
$scope.data =[];
$scope.data = $scope.choices;
//alert('companyId=='+$scope.app.company_id);
$scope.item = [];
var newItem = {};
for( var i in $scope.choices)
{
newItem= $scope.choices[i];
$scope.item.push(newItem);
}
console.log( "item",$scope.item);
var fd = new FormData();
fd.append('action', APP_ACTION.INSERT_CHECKLIST);
fd.append('company_id', $scope.app.company_id);
fd.append('user_id', $cookieStore.get('userData').id);
fd.append('checkListName',$scope.checklist_name);
fd.append('checkListData',$scope.item);
httpCall.remoteCallPost($scope, $http, fd, function (record)
{
alert('data========'+record.data);
}, function (message)
{
alert('Error');
});
}
$ scope.item中的数据就像这样
[
0:{id: "choice1", number: "1", shortext: "1", longtext: "1", photo: true},
1:{id: "choice2", number: "2", shortext: "2", longtext: "2"},
2:{id: "choice3", number: "3", shortext: "3", longtext: "3"}
]
当我在php后端收到请求时,我得到了这样的数组
Array
(
[action] => insertCheckList
[company_id] => 2
[user_id] => 13
[checkListName] => sadasdsa
[checkListData] => [object Object],[object Object],[object Object]
)
我的问题是如何访问作为对象发送的数据,或者我以错误的方式发送数据,如果我以错误的方式发送数据,那么如何以正确的方式发送数据?