我有问题,我确实将字段表格设置为数组。示例:响应中的字段dfp_interest
为[]。因此,我必须将数据设置为阵列吗?我做到了,并在console.log中取得了成功。结果像 -> ["5","6"]
,但是当我在angular.fromJson
中处理并使用$http
发送时,我的params dfp_interest是字符串而不是数组。我错了吗 ?给我解决方案还是我犯了一些错误?
这是我在api
中发送参数的过程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("");
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));