0

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/pushposition.id 时,它会抛出异常 Error: $scope.exportvideo.push is not a function

如何将 position.id 值添加到现有的 json 字符串?

4

1 回答 1

0

Push 用于将项目附加到数组。看起来您想将属性添加到 json 对象。做就是了

$scope.exportvideo.id = $scope.data.selectedPosition.id;
于 2016-07-06T10:12:56.390 回答