[jQuery] json, select-option 동적 생성
처음 페이지를 호출할때 코드값을 조회하고 페이지에서 로딩될때 코드값을 추가해서
select 생성.
데이타 이동은 json으로...
------------------------------------------------------------------------------
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public ActionForward execInit(
BaseActionMapping mapping,
BaseValidatorForm form,
HttpServletRequest req,
HttpServletResponse res)
throws Exception {
Bean beanList = mgt.getTypeCdList(C0001);
JSONArray arrJson = new JSONArray();
for(int i=0 ; i<beanList.size() ; i++) {
CodeDto dto = (CodeDto)beanList.get(i);
JSONObject jObj = JSONObject.fromObject(dto);
arrJson.add(jObj);
}
req.setAttribute("typeListJson", arrJson.toString());
return mapping.findForward("init.form");
}
------------------------------------------------------------------------------
<%
String typeJson = (String)request.getAttribute("typeListJson");
%>
String typeJson = (String)request.getAttribute("typeListJson");
%>
<script type="text/javascript">
$(document).ready(function() {
// 유형 선택 생성
var jaonArr = $.evalJSON('<%=typeJson%>');
$("#typeSelect").html("");
for(var i=0 ; i<jaonArr.length ; i++) {
var o = jaonArr[i];
var paramLi = "";
paramLi += "<option value='"+o.cdNo+"'>";
paramLi += o.cdNm;
paramLi += "</option>";
$("#typeSelect").append(paramLi);
}
});
</script>
------------------------------------------------------------------------------
...
<dl>
<dt>유형</dt>
<dd>
<p>선택하세요</p>
<select id="typeSelect" size="5"> </select>
</dd>
</dl>
...
------------------------------------------------------------------------------
댓글