【问题标题】:hide and show a table column隐藏和显示表格列
【发布时间】:2013-03-13 21:08:54
【问题描述】:

我需要根据从弹簧控制器传递的模型对象隐藏最后一列复选框。如果模型值为“isAll”,则应隐藏任何其他值,如果它应该是可见的,我已经尝试过,但到目前为止失败了。我不确定我是否正确地从控制器传递了值。帮助!

控制器:

    System.err.println("Type is: " + formbean.getType());
System.err.println("IscCode is: " + formbean.getForecastIsc());
System.err.println("ActualIscCode is: " + formbean.getActualIsc());
System.err.println("labelNbr is: " + formbean.getLabelNbr());
System.err.println("senderOp is: " + formbean.getSenderOp());       
System.err.println("senderLastName is: " + formbean.getSenderLastName());
System.err.println("receiverOp is: " + formbean.getReceiverOp());
System.err.println("receiverLastName is: " + formbean.getReceiverLastName());


    summary = summarySelectDao.getSummary(formbean);    
    if(summary == null || summary.size() == 0){         
        errorMessage = "No Parcel Analysis Cases Found!";
return new ModelAndView("redirect:/analysis/analysisSelection? hasError=true");
    }else{
    logger.info("Total " + summary.size() + " analysis cases found from DB.");
        model.addObject("summary", summary);
        model.addObject("isAll", true);  //BASED on this model if true
    }

    return model;       

JSP:

<td class="ct"<c:out value="${summary.country}" /></td>
 <td class="sc" <c:out value="${summary.source}" /></td>
 <td  class="cb" <input type="checkbox" value=""> </td>

JS:

$(document).ready(function() {
$(".cb").hide();    
}); 

HTML:

   <div id=table1>
<table id="summaryTable" class="sortable">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th>Bar Code</th>
            <th>Origin</th>
            <th>Sender Name</th>
            <th>Recipient Name</th>
            <th>USPS Mail<br>Receipt Date</th>
            <th><br>Load Date</th>
            <th>Fore-<br>cast<br> ISC</th>
            <th>Act-<br>ual<br> ISC</th>
            <th>Country</th>
            <th>Source</th>
<th class="cb"><input type="button" id="btnSelectAllCbl" name="selectCheckBox"
            value="Update"> </th>
        </tr>
    </thead>
    <tbody> 
        <tr>

                <tr>
<td bgcolor='yellow'>P
    </td>
    <td bgcolor='yellow'><a href="AnalysisController?value=xxxxx">xxxxx
    </a>
    </td>
    <td bgcolor='yellow'>55025
                    </td>
    <td bgcolor='yellow'>xxxx
                    </td>
    <td bgcolor='yellow'>SON
    </td>
 <td  bgcolor='yellow'>
        </td>
<td bgcolor='yellow'>2013/02/11 060205
</td>
<td bgcolor='yellow'>ORD
                    </td>
<td bgcolor='yellow'>ORD
                    </td>
                    <td  bgcolor='yellow'>SINGAPORE
                    </td>
                    <td  bgcolor='yellow'>RECIPIENT
                    </td>
                    <td class="cb" bgcolor='yellow'><input
                        type="checkbox" value="">
                    </td>

【问题讨论】:

  • 您是根本不显示 HTML,还是只是不隐藏最后一列?如果您尝试在单元格中显示值,我认为您的 JSP 中的 HTML 无效。您需要在
  • 正确关闭时它应该可以工作,检查这里:jsfiddle.net/D2LR3
  • 对不起,我可能让你有点困惑。隐藏功能工作正常,但我需要的是它仅在从控制器传递的值为“isAll”时隐藏该列,否则它应该显示该列。现在即使“isAll”为假,它也隐藏该列。跨度>

标签: jquery jsp spring-mvc controller


【解决方案1】:

最简单的方法:使用&lt;c:if&gt; 打印/不打印列:

<c:if test="${isAll}">
    <td  class="cb"><input type="checkbox" value=""></td>
</c:if>

对列标题也这样做。

【讨论】:

  • 谢谢! @Luiggi Mendoza 所以通过使用 我还需要使用 jquery 吗?如果是的话,你能详细说明我将如何编码那部分..
  • 不,只删除jquery部分。
猜你喜欢
相关资源
最近更新 更多
热门标签