[英]Wrong object creation in Angular post
我有一个AngularJS控制器,看起来像这样:
function MainController($scope, $http) {
//code for HTTP Get
$scope.SelectionChanged = function () {
//some initialization code
$http.post("/api/cinema", { film: $scope.film })
.then(function (result) {
//success
}, function (result) {
//failure
});
}
}
SelectionChanged是绑定到作用域以使某些选择元素响应的功能。
我可以在提琴手中看到传递的对象类似于:
{"film":["HO00000335"]}
但我希望是:
{"film":"HO00000335"}
我怎样才能做到这一点?
开斋节:
现在,当我在列表中进行选择时,会在提琴手中得到以下内容:
POST http://localhost:18669/api/cinema HTTP/1.1
Host: localhost:18669
Connection: keep-alive
Content-Length: 23
Accept: application/json, text/plain, */*
Origin: http://localhost:18669
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://localhost:18669/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
{"film":["HO00000262"]}
看起来$scope.film
是一个数组。
尝试这个:
function MainController($scope, $http) {
//code for HTTP Get
$scope.SelectionChanged = function () {
//some initialization code
$http.post("/api/cinema", { film: $scope.film[0] }) // note the [0]
.then(function (result) {
//success
}, function (result) {
//failure
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.