3

我正在使用数据表编辑器。当我尝试编辑并将其发布到服务器时,该行不断消失。刷新页面后,可以看到实际更新的数据。

这是我的代码片段。

var editor = new $.fn.dataTable.Editor({
    ajax: "/ajax/clips/edit",
    table: "#clips_table",
    idSrc: "id",
    fields: [
        {
            label: "Id",
            name: "id",
            type: "hidden"
        },
        {
            label: "Player",
            name: "player",
            type: "select",
            options: [
                { label: "Rooney", value: "Rooney" },
                { label: "Bale", value: "Bale" }
            ]
        }
    ]
 },
     editorOpenValues;

 editor.on('open', function() {
     editorOpenValues = JSON.stringify(editor.get());
 })
 .on('preBlur', function () {
     if (editorOpenValues !== JSON.stringify(editor.get())) {
         this.submit();
     }
 });

 $('#clips_table').DataTable({
     dom: "lfrtip",
     order: [[2, "asc"]],
     columns: [
         {data: "id"},
         {data: "name"},
         {data: "start"},
         {data: "stop"},
         {data: "player"}
     ]
 });

 $('#clips_table').on('click', 'tbody td.player', function () {
     editor.inline(this);
 });

这是服务器端脚本返回的 JSON 数据:

{
    "data": {
        "0": {
            "id": "322",
            "name": "Scoren 001",
            "start": "00:11",
            "stop": "00:31",
            "player": "Rooney"
        }
    }
}

这个错误的可能原因是什么?

4

1 回答 1

2

最后,我想通了。

我差点忘了检查版本兼容性。我将 v1.5.1 用于数据表编辑器。当我将它升级到 v1.5.4(最新版本)时,错误消失了。

学过的知识!- 当我遇到烦人的错误时,我会先进行版本检查。

于 2016-01-11T18:08:19.350 回答