HTML
<form ng-submit="exportVideoForm()">
<input type="text" class="form-control" ng-model="exportvideo.exportName" required>
<input type="text" class="form-control" ng-model="exportvideo.description" required>
<select class="form-control" name="selectposition" id="selectposition"
ng-options="position.name for position in data.waterMarkImgPosition track by position.id"
ng-model="data.selectedPosition"
ng-change="changePosition(data.selectedPosition)"
required>
<option ng-show="false" value="">Please Select</option>
</select>
</form>
Ctrl
$scope.exportVideoForm = function() {
$scope.data.selectedPosition.id = 'lowerLeft';
$scope.exportvideo = $scope.exportvideo.push($scope.data.selectedPosition.id); //push watermark position in json string
$scope.exportVideoJson = angular.toJson($scope.exportvideo); //convert to json
};
输出
console.log($scope.exportVideoJson) = {"exportName":"myname","description":"mydesc"}
当我尝试concat/push
position.id 时,它会抛出异常
Error: $scope.exportvideo.push is not a function
如何将 position.id 值添加到现有的 json 字符串?