<div class="cs-clear cs-ib">
<span style="float: left;margin-left:-20px;">
<label for="game">游戏名称:</label>
</span>
<span style="float: left;">
<select id="game" name="game" οnchange="GameServer.changeServer(this.value);gameServerChannelInsert.reGetChannels('${basePath}');">
<c:forEach items="${gameListMap}" var="map" varStatus="status" >
<option value="${map.key }" <c:if test="${ map.key==game}">selected </c:if> >${map.value }</option>
</c:forEach>
</select>
</span>
<span style="float: left;">
<label for="server_null">游戏服务器:</label>
</span>
<span style="float: left;">
<select id="server_null" name="gameServer" style="display:none; " disabled="disabled" οnchange="gameServerChannelInsert.reGetChannels('${basePath}')">
<option value="null">全部</option>
</select>
<c:forEach items="${gameServerMap}" var="serverMap" varStatus="status" >
<select id="server_${serverMap.key}" name="gameServer" style="display:none;" disabled="disabled" οnchange="gameServerChannelInsert.reGetChannels('${basePath}') ">
<option value="null">全部</option>
<c:forEach items="${serverMap.value}" var="gameServerPO" varStatus="status" >
<option value="${gameServerPO.pk.gameServer }" <c:if test="${ map.key==gameServer}">selected </c:if> >${gameServerPO.serverName }</option>
</c:forEach>
</select>
</c:forEach>
<input type="hidden" id="lastGameId" name="lastGameId" value='${game }'/>
<input type="hidden" id="lastGameServer" name="lastGameServer" value='${gameServer }'/>
</span>
<span style="float: left;margin-left:-35px;">
<label for="channel_null">频道:</label>
</span>
<span style="float: left;" >
<select id="channel_null" name="channelId" style="display:none; " disabled="disabled">
<option value="null">全部</option>
</select>
<select id="channelId" name="channelId" >
<option value="null">全部</option>
<c:forEach items="${gameServerChannels}" var="item" varStatus="status" >
<option value="${item.channelId}" <c:if test="${item.channelId==channelId}">selected </c:if>>${item.channelId}</option>
</c:forEach>
</select>
</span>
</div>
==============================================================================
var gameServerChannelInsert = {
"reGetChannels" : function(path) {
var game = document.getElementById("game").value;
var gameServerId = "server_"+game;
var gameServer = document.getElementById(gameServerId).value;
var url = path+'specialServer/reGetChannels.do';
var queryData = $("#queryForm").serializeArray(); //把表单元素序列化成json格式的数据
$.ajax({
type: "POST",
url: url,
data: queryData, // 相当于提交表单数据(后台能接收)
async: true,
cache: false,
// dataType: "json",
success: function(data){
$("#channelId").html(data);
}
});
},
}
==============================================================================
/**
* 异步获取频道列表
* @param response
* @param game
* @param gameServer
* @throws IOException
*/
@RequestMapping
public void reGetChannels(HttpServletResponse response, String game,String gameServer) throws IOException {
List<DimGameServerChannel> gameServerChannels = dimGameServerChannelService.getGameServerChannel(game, gameServer);
List<String> channels = new ArrayList<String>();
for (DimGameServerChannel gameServerChannel : gameServerChannels) {
channels.add(gameServerChannel.getChannelId());
}
String channelsHtml = buildChannelsToHtml(channels);
response.setContentType("text/plain; charset=gbk");
PrintWriter writer = response.getWriter();
writer.write(channelsHtml);
writer.flush();
}
private String buildChannelsToHtml(List<String> channels) {
StringBuilder channelsHtml = new StringBuilder();
channelsHtml.append("<option value='null'>全部</option>");
for(String channel : channels) {
if(StringUtils.equals("null", channel)) {
continue;
}
channelsHtml.append("<option value='").append(channel).append("'>").append(channel).append("</option>");
}
return channelsHtml.toString();
}