2016-07-06 9 views
0

HTMLAngularJS - 私はにしようとするとJSON文字列に

<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"} 

を選択したモデルのオプションを追加します。 $のscope.exportvideo.push私は、既存のJSON文字列にposition.id値を追加するにはどうすればよい機能

ではありません:position.idが、それは例外 エラーがスローされますか?

答えて

0

プッシュは、項目を配列に追加するためのものです。 jsonオブジェクトにプロパティを追加するように見えます。ちょうど

$scope.exportvideo.id = $scope.data.selectedPosition.id; 
+0

複数のプロパティの場合、このように割り当てる必要がありますか?他の選択肢? – Slimshadddyyy

+0

また、$ scope.exportvideo ['id'] = $ scope.data.selectedPosition.id;を実行することもできます。 – Srijith

+0

これはまた、 '$ scope.videoFormat = $ scope.data.selectedFormat.id? – Slimshadddyyy

関連する問題