javascript - DataTables.Net - 有没有办法从数据中设置属性?

标签 javascript jquery ajax datatables

我想要做的是从ajax数据设置“column”属性

json 数据具有“data”和“columns”属性,因此要提取数据,我需要这样的东西。

primaryTable = $('#example').DataTable({
            "ajax": "data.txt"
        });

假设 txt 文件有一个列属性,可以定义列 {"data":"Name"} 等,有没有办法可以引用它?

primaryTable = $('#example').DataTable({
            "ajax": "data.txt"
            "columns" : data.columns
        });

有什么办法可以引用吗? 另一种方法是使用 jQuery.ajax 或 getJSON,我已经使用过它们,但无法弄清楚如何正确加载数据。

谢谢

最佳答案

看起来(至少截至 2013 年 11 月),使用单个 AJAX 调用是不可能完成的。 Source

The answer is no - I'm sorry to say you cannot do that in DataTables at this time. The full range of options that are available in aoColumns cannot be represented in JSON (specifically functions) so there is no method for this in DataTables at this time. I might relax that in future, but at the moment you'll need to make an Ajax request to get the column information yourself. Allan

您可以通过发出两个连续的 AJAX 调用来解决该问题:第一个用于获取数据以填充表标题列,第二个用于数据本身。

该链接还提供了示例调用。

关于javascript - DataTables.Net - 有没有办法从数据中设置属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26372469/

相关文章:

javascript - 使用javascript在不前进的情况下使用按键记录qualtrics中的 react 时间

javascript - Rails AJAX 部分无需提交表单

jquery - 未捕获的类型错误 : Cannot read property 'ajax' of undefined

javascript - 将对象添加到 inlineImages sendEmail 参数

javascript - 在html中包含外部js和css文件

jquery - 不以邮件形式发送信息?

php - 如何使用 opencart 将一些变量发布到文件?

javascript - Ajax 禁用表单字段

javascript - Prop 未传递给 Child

javascript - javascript 中的闭包和词法环境