0

我有一个 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"]}
4

1 回答 1

1

它看起来像$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
            });
    }
}
于 2013-09-10T12:01:06.393 回答