我有问题,我确实将字段形式设置为数组。示例:响应中的字段dfp_interest
为[]。那么,我必须将我的数据设置为数组吗?我在console.log中做了并取得了成功。结果如 - > ["5","6"]
但是当我在angular.fromJson
处理并且我使用$http
发送时,我的参数dfp_interest是字符串而不是数组。我错了吗 ?给我解决方案还是我犯了一些错误?
这是我在API中发送params的过程
var a = angular.fromJson({
"data" : "{\"username\": \"newshubid\", \"data\":{\"_id\": \""+ $scope.id +"\",\"label\": \""+ $scope.label +"\",\"active\": \""+ $scope.active +"\",\"parent_id\": \""+ $scope.parent_id +"\",\"level\": \""+ $scope.level +"\",\"meta_title\": \""+ $scope.meta_title +"\",\"meta_description\": \""+ $scope.meta_description +"\", \"meta_keyword\": \""+ $scope.meta_keyword +"\", \"dfp_interest\": \""+ $scope.tes +"\"}}"
});
var param = $.param(a);
HttpService("POST", url, param, function(response){
alert(response.message);
});
这是dfp_interest
$scope.tes = [5, 6];
$scope.testarray = $scope.tes.join("");
答案 0 :(得分:1)
angular.fromJson
接受一个字符串参数,表示你的代码应该是;
var data = {username: 'newshubid',
data: { id: $scope.id,
label: $scope.label,
active: $scope.active,
parent_id: $scope.parent_id,
level: $scope.level,
meta_title: $scope.meta_title,
meta_description: $scope.meta_description,
meta_keyword: $scope.meta_keyword,
dfp_interest: $scope.tes }
};
var a = angular.fromJson(JSON.stringify(data));