【发布时间】:2015-12-27 18:40:10
【问题描述】:
我有一个表单,我通过 WebApi 显示我的数据库中的值。其中一个控件将具有值数组。我有一个用户可以编辑和保存它的场景(PUT 函数)。
控制器:
$scope.Put= function () {
$scope.item1 = [];
$scope.item1 = $scope.Cast.split(',');
var Movie1 = {
_movieId: $scope.MovID,
_title: $scope.Movtitle,
_releaseDate: $scope.Movdate,
_rating: $scope.Movrate,
_cast: $scope.item1
};
var Result-= MyService.Update($scope.MovID, Movie1);
Result.then(function (pl) {
$scope.Message = "Updated Successfuly";
}
HTML:
<input type="text" ng-model="MovID" class="spacebox" size="30" /> <br />
<input type="text" ng-model="Movtitle" class="spacebox" size="30" />
<input type="text" ng-model="Cast" class="spacebox" size="30" />
<input type="button" ng-value="Edit" ng-click="enable()" style="margin-left: 250px; border-radius: 5px;" />
Cast 输入是一个字符串数组,如果用户编辑它和SAVE,则可以完美工作,但是当我尝试编辑一些其他字段(如 ID、标题)并继续 save 而不修改 Cast我时收到类似$scope.Cast.split is not a function 的错误。为什么以及如何解决。
【问题讨论】:
-
这个错字是
Cast1还是Cast? -
是的……我已经编辑过了。谢谢
-
在控制器中定义即可:$scope.Cast = '';
标签: javascript html angularjs asp.net-web-api