如何将多个选择转换为json并将其绑定到范围?请帮帮我。
这是我的剧本:
<script type="text/javascript">
var app = angular.module('formSubmit', []);
app.controller('FormSubmitController',[ '$scope', '$http', function($scope, $http) {
$scope.list = [];
$scope.headerText = 'AngularJS Post Form Spring MVC example: Submit below form';
$scope.submit = function() {
var formData = {
"amenities" : $scope.amenities,
};
var response = $http.post('/property', formData);
response.success(function(data, status, headers, config) {
$scope.list.push(data);
});
response.error(function(data, status, headers, config) {
alert( "Exception details: " + JSON.stringify({data: data}));
});
//Empty list data after process
$scope.list = [];
$scope.$setPristine();
};
}]);
</script>
这是我正在使用的多项选择:
<div class="col-md-6">
Amenities <a href="#" data-toggle="tooltip"
data-placement="bottom"
title="Press Ctrl key to select multiple Amenities"><img
src="<c:url value="/resources/images/info-icon.png"/>" /></a>
<!-- <select name="amenities" class="form-control" id="property_status" onchange="setDyna()" required> -->
<select name="amenities" class="form-control" id="amenities"
onchange="setDyna()" data-ng-model="amenities" multiple>
<option value="pool">Swimming Pool</option>
<option value="park">Playground/park</option>
<option value="gym">Gym/Fitness Center</option>
<option value="security">Gate Security</option>
<option value="club">Club House</option>
<option value="intercom">Intercom</option>
<option value="parking">Visitor Parking</option>
<option value="lift">Lift</option>
</select>
</div>