如何提取传递给jQuery的对象的属性

时间:2018-09-29 22:32:50

标签: java spring jsp

我正在使用JSP,并且选择了医生姓名和返回值选项,并且返回值是医生的对象,具有诸如姓名,专长,地址和电话之类的属性。这是选择代码。

<select class="form-control" name="selectedPhysician"  id="selectedDoctor" onchange="populatePhysicianInfo()"> 
    <option value="" >Select Doctor in the List</option>
    <c:forEach items="${listAllPhysicians }" var="thePhysician" >
        <option value= "${thePhysician}">${thePhysician.physicianName}</option>
    </c:forEach>
</select>

populatePhysicianInfo()是jQuery函数,我想提取通过列表选项传递的对象的属性。这些属性将弹出到适当的表单元素。如何实现财产的提取?

功能如下:

$(document).ready(function() {
     var doctorObj = new Object
    $("#selectedDoctor option").filter(function(){

        return $(this).val() == $("#name").val();
    }).attr('selected', true);

     $('#selectedDoctor').change(function(){

         doctorObj = $(this).val();
         alert(doctorObj);
         /*
         $('#name').doctorObj['physicianName'];
         $('#specialty').doctorObj['physicianSpecialty'];*/

     });


});

警报用于检查目的,其输出看起来像这样。

Physician [id=22, physicianName=Joe Nguyen, physicianPhone=512-244-9024, physicianAddress=ARC Round Rock, 940 Hesters Crossing Road, Round Rock, TX 78681, physicianSpecialty=Primary Doctor]

0 个答案:

没有答案
相关问题