在数据表中发送 JSON 对象 aaData 而不是数组 [英] Sending JSON Objects in DataTables aaData instead of arrays

查看:27
本文介绍了在数据表中发送 JSON 对象 aaData 而不是数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序上使用了 jquery DataTables 插件,到目前为止我对这个功能非常满意,尽管我希望将数据传递给 aaData 属性.

目前它似乎只接受 javascript 数组为

<代码> [['价值','价值','价值'],...,...,]

我希望能够使用对象而不是数组,因为它会更干净并帮助我扩展一些过滤,我正在做的更容易.我如何向它传递一个看起来像这样的 javascript 变量(不是通过 AJAX 加载).

<预><代码>[{'id':1,'status':0,'name': 'hello world'},...,...,]

尝试将 sAjaxSource 与局部变量一起使用的示例http://live.datatables.net/utecax/edit#

尝试将对象数组与 aaData 一起使用的示例http://live.datatables.net/iyavud/5/edit

解决方案

可以通过aaData属性传入对象数组,然后使用aoColumns属性定义哪一列应该接收哪些数据

 $('#example').dataTable({bProcessing":真,"aaData": data,//<-- 你的对象数组"aoColumns": [{ "mData": "render_engine" },//<-- 在对象内部使用哪些值{mData":浏览器"},{mData":平台"},{ "mData": "enging_version" },{mData":css_grade"}]});

I am using the jquery DataTables plugin on my application and I am really happy so far with the functionality although I would like to pass the data slightly differently to the aaData attribute.

currently it only seems to accept the javascript array as

 [
    ['value','value','value'],
    ...,
    ...,
]

I would like to be able to use an object rather than arrays because it will be cleaner and help me extend some filtering I am doing easier. how can I pass it a javascript variable that looks like this ( not loading via AJAX ).

[
   {'id':1,'status':0,'name': 'hello world'},
   ...,
   ...,
]

Example trying to use sAjaxSource with local variable http://live.datatables.net/utecax/edit#

Example trying to use array of objects with aaData http://live.datatables.net/iyavud/5/edit

解决方案

You can pass in the array of objects via aaData property, then use aoColumns property to define which column should recieve which data

  $('#example').dataTable({
        "bProcessing": true,
        "aaData": data,// <-- your array of objects
        "aoColumns": [
            { "mData": "render_engine" }, // <-- which values to use inside object
            { "mData": "browser" },
            { "mData": "platform" },
            { "mData": "enging_version" },
            { "mData": "css_grade" }
        ]
  });

这篇关于在数据表中发送 JSON 对象 aaData 而不是数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆