2011-05-03 68 views
0

这是显示一个窗口与columns.Each列中的代码,我的jsp页面的对应于一种形式如何在jquery中将值设置回地图?

<%@include file="/WEB-INF/jsp/include/pagedirectives.jsp"%> 

<div style="background: #D6E8FF; padding: 10px;" class="advanced_search"> 
<%@include file="/WEB-INF/jsp/include/page.topmessagebox.jsp"%> 

<table class="form" cellspacing="0" id="requestSubmissionEform"> 
    <tbody> 
     <tr> 
      <td class="label"><b>Label</b></td> 
      <c:forEach var="i" begin="1" end="5" step="1" varStatus ="status"> 
      <th id="form_${i}" class="label" align="left"><b>Form ${(pageNumber * 5) + i}</b></th> 
      </c:forEach> 
     </tr> 

     <c:forEach items="${eformDetailsList}" var="eformDetails" 
      varStatus="status"> 

      <tr id="serviceTypeWithEform"> 
       <td class="label"> 
        <label for="${eformDetails.id}_0"><c:out value="${eformDetails.label}" /></label> 
        <input type="hidden" id="label_${eformDetails.id}_0" value="${eformDetails.label}" name="label_0"></input> 
        <input type="hidden" id="index_${eformDetails.id}_0" value="${eformDetails.id}" name="index_0"></input> 
       </td> 
       <c:if test="${eformDetails.controlType==1}"> 
        <td id="Col0" style="visibility: visible;"> 
         <input id="eformDetail_${eformDetails.id}_0" class="eformDetail" type="text" value="" name="form_0"></input> 
        </td> 
        <td id="Col1" style="visibility: visible;"> 
         <input id="eformDetail_${eformDetails.id}_1" class="eformDetail" type="text" value="" name="form_1"></input> 
        </td> 
        <td id="Col2" style="visibility: visible;"> 
         <input id="eformDetail_${eformDetails.id}_2" class="eformDetail" type="text" value="" name="form_2"></input> 
        </td> 
        <td id="Col3" style="visibility: visible;"> 
         <input id="eformDetail_${eformDetails.id}_3" class="eformDetail" type="text" value="" name="form_3"></input> 
        </td> 
        <td id="Col4" style="visibility: visible;"> 
         <input id="eformDetail_${eformDetails.id}_4" class="eformDetail" type="text" value="" name="form_4"></input> 
        </td> 
       </c:if> 
      </tr> 

     </c:forEach> 
     <c:if test="${empty eformDetailsList}"> 
      <tr id="serviceTypeWithNoEform"> 
       <td><b>There is no eform associated with this Service Type</b></td> 
      </tr> 
     </c:if> 

    </tbody> 
</table> 

这是用来从JSP页获得的值的jquery:

var labels0=$('input[name="label_0"]').map(function(){ 
    return $(this).val() }).get(); 
var index0=$('input[name="index_0"]').map(function(){ 
    return $(this).val() }).get(); 
var fields0 = $('input[name="form_0"]').map(function(){ 
    return $(this).val() }).get(); 
var fields1 = $('input[name="form_1"]').map(function(){ 
    return $(this).val() }).get(); 
var fields2 = $('input[name="form_2"]').map(function(){ 
    return $(this).val() }).get(); 
var fields3 = $('input[name="form_3"]').map(function(){ 
    return $(this).val() }).get(); 
var fields4 = $('input[name="form_4"]').map(function(){ 
    return $(this).val() }).get(); 

点击保存,我保存了值。当我再次打开表单时,我希望保存的值重新显示在我的文本框中。是否有方法将值重新设置回地图?

+0

你应该这样做服务器端(JSP),填充您的foreach中的值 – 2011-05-03 06:36:07

回答

0

(我想你应该用JSP做吧..) 无论如何,假设你有JS数组:

var label_0_values = ['value 1', 'value 2', ...]; 

使用jQuery,你会填充像这样:

$('input[name="label_0"]').each(function(i){ 
    $(this).val(label_0_values[i]); 
}); 

而且相同的为您的其他输入

希望这会有所帮助。干杯

+0

它进入循环,但我无法设置值..不知道为什么。我正在尝试此操作为form_0 – user735566 2011-05-03 14:31:19

相关问题