【问题标题】:Using Datatables, can I get the data out of the table to submit to a server?使用 Datatables,我可以从表中获取数据以提交到服务器吗?
【发布时间】:2012-02-22 22:02:54
【问题描述】:

我想要整个表的 .serialize() 之类的东西。我正在使用DataTables 并希望能够得到一个漂亮的嵌套数组。

例如,我有下表:

<table>
   <thead>
      <tr>
         <th>
            user
         </th>
         <th>
            first_name
         </th>
      </tr>
    </thead>
    <tbody>
       <tr>
          <td>
             joey
          </td>
        </tr>
        <tr>
          <td>
             Joey
          </td>
        </tr>
    </tbody>
</table>

我希望能够使用该表调用函数并获得类似的数组

[
   {
      'user': 'joey', 
      'firstname':'Joey'
   }
]

有什么办法可以通过混合中的数据表插件来做到这一点。它对桌子做了一些奇怪的事情,所以我遇到的功能在它上面不起作用。

【问题讨论】:

    标签: jquery html datatables html-table


    【解决方案1】:

    我不知道 serialize 方法,但如果您没有想法,您可以使用this function 在处理数据时创建自己的数组。

    所以你创建了一个全局数组,在你的数据表创建方法中你有

    $('#tablename').dataTable({
        "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                    AddToArray(aData);
                    return nRow;
          }
    });
    
    function AddToArray(aData){
        var user = aData[0];
        var name = aData[1];
        //add them to your array
    }
    

    抱歉,我的 javascript 非常糟糕,但希望它可以引导您朝着正确的方向前进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 2014-10-26
      相关资源
      最近更新 更多