从select选项中获取对象--JQuery

时间:2016-06-04 15:50:51

标签: java jquery

我有控制器在哪里方法:

@RequestMapping(value = "carListForSelect", method = RequestMethod.GET,produces = "application/json")
    public ResponseEntity<List<CarBD>> getCarListForSelect() {
        List<CarBD> carList = carService.getAll();
        HttpStatus httpStatus = carList != null ? HttpStatus.OK : HttpStatus.NOT_FOUND;
        return new ResponseEntity<List<CarBD>>(carList, httpStatus);
    }

此方法提供选择(我选择汽车的地方)

 <div class="form-group">
            <label for="carListSelect">Car name</label>
            <select class="form-control" id="carListSelect">

            </select>
$.ajax({
        url:'car/carListForSelect',
        type:'GET',
        contentType: 'application/json;charset=UTF-8',
        success: function( data ) {
            $.each(data, function(i, value) {
                $('#carListSelect').append($('<option></option>`').text(value.carName).attr('value',value));
            });
        }
    });

如何从这个选择对象Car获取此JSON:

var exchange = {
            "car": {
                CAR OBJECT
            },
            "exchangeDate": $('#exchangeDateInput').val(),
            "exchangePrice": $('#exchangePriceInput').val(),
            "exchangeDescription": $('#exchangeDescriptionInput').val(),
            };
        };

0 个答案:

没有答案