【问题标题】:cache populates wrong checkboxs in jQuery datatable MVC缓存在 jQuery 数据表 MVC 中填充错误的复选框
【发布时间】:2013-08-01 16:58:19
【问题描述】:

我的 mvc 视图有一个使用 .datatable 的表。每行有很多列,名称...和一个复选框。如果我按原始名称以外的另一列对表进行排序然后导航离开然后按回,缓存使用名称排序将视图模型数据加载到表中,但是缓存似乎正在根据先前检查的行检查复选框使用不同的排序。

例如

(原创)

name | number |checked
A    |   3    |
B    |   1    |   X
C    |   2    |

按数字排序(.datatable)

name | number |checked
B    |   1    |   X
C    |   2    |
A    |   3    |

转到新页面然后返回

我在 .ready 之后等待 javascript,这样我就可以看到未设置样式的表格

name | number |checked
A    |   3    |   X
B    |   1    |   
C    |   2    |

然后一旦数据表运行

name | number |checked
B    |   1    |   
C    |   2    |
A    |   3    |  X

我在 chrome 和 IE 中测试过,问题只出现在 chrome 中。

<table class="table table-striped table-bordered" style="text-  transform:none!important">
        <thead>
            <tr>
                <th>Name
                </th>
                <th>Number
                </th>
                <th>Checked
                </th>
</tr>
        </thead>
        <tbody>

            @if (@Model.records.Count() > 0)
            {
                foreach (var item in @Model.records)
                {
                <tr>
                    <td>@item.Name</td>
                    <td>@item.number</td>
                    <td>@Html.CheckBox("chkhide", @item.IsHidden, new { @class = "hide_check", id = item.Id })</td>

 </tr>
                }
            }

        </tbody>
    </table>

<script type="text/javascript">
jQuery(document).ready(function () {

    $('.table').dataTable(
      {
          "sDom": 'T<"clear">lfrtip',
          "oTableTools": {
              "sSwfPath": "../../../../Content/DataTables-1.9.4/extras/TableTools/media/swf/copy_csv_xls_pdf.swf",
              "aButtons": ["copy", "csv"]
          },
          "bPaginate": false,
          "bSortCellsTop": true,
          "bSortClasses": false,
          "bStateSave": true
      });

【问题讨论】:

  • 需要一些代码或 js 小提琴,否则我只是在微风中拍打为什么

标签: jquery asp.net-mvc datatables browser-cache


【解决方案1】:

通过强制服务器端刷新模型数据解决了这个问题。它看起来只是一个与 chrome 缓存系统的数据表接口的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    相关资源
    最近更新 更多