springMVCフォーム連動処理はradio連動をクリックしてselectオプションを変更します.
いくつかの業務内容に関連していますので、多くの説明と関連コードを貼り付けました.
タスク:ラジオの単一選択ボックスをクリックして選択し、動的連動リフレッシュオプションのアイテムを選択します.
フロントjs:
タスク:ラジオの単一選択ボックスをクリックして選択し、動的連動リフレッシュオプションのアイテムを選択します.
フロントjs:
function getRooms(){
var location = GetRadioValue('location');
$.ajax({
type: "POST",
url: "${ctx}/oa/meeting/getRooms",
data: { //
location: location
},
dataType: 'json',
success: function(data) {
$("#meetingRoom").empty();
$.each(data, function(index,item){
$("#meetingRoom").append("<option class='required' value='"+item.id+"'>"+item.name+"</option>")
});
}
})
}
/* check radio */
function GetRadioValue(RadioName){
var obj;
obj = document.getElementsByName(RadioName);
if (obj != null) {
var i;
for (i = 0; i < obj.length; i++) {
if (obj[i].checked) {
return obj[i].value;
}
}
}
return null;
}
spring MVCフォームを採用したjsp: <div class="control-group">
<label class="control-label"> <font color="red" size="4">*</font>:</label>
<div class="controls">
<form:radiobuttons path="location" items="${allLocations}" delimiter=" "
onclick='getRooms()'/>
</div>
</div>
<div class="control-group">
<label class="control-label"> <font color="red" size="4">*</font>:</label>
<div class="controls">
<form:select path="room" id="meetingRoom">
<form:option value="" label=" "/>
<form:options items="${allRooms}" itemLabel="name" itemValue="id" htmlEscape="false" class="required"/>
</form:select>
</div>
</div>
controllerの関数は、フロントrequestによって調べられ、jsonデータに戻ります. @RequestMapping(value="getRooms")
public @ResponseBody List<Room> getRooms(String location){
String locat = location;
try {
locat = URLDecoder.decode(location, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<Room> rooms = roomService.findByLocation(locat);
return rooms;
この機能を実現するためのキーコードは全部その中にあります.参考だけにして、同じ需要の人を助けたいです.