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

问题描述

我正在使用我的应用程序中的jQuery DataTables插件,尽管我希望将数据稍微传递给aaData属性,但我真的非常高兴。



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

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

我想要使用一个对象而不是数组,因为它会更干净,并帮助我扩展一些过滤我更容易。如何传递一个看起来像这样的JavaScript变量(不通过AJAX加载)。

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

尝试使用sAjaxSource与本地变量的示例



尝试使用aaData
的对象数组的示例

解决方案

您可以通过aaData属性传递对象数组,然后使用aoColumns属性来定义哪个列应该收到哪些数据



$ $ $ $ $ $$$$$$$$ - 你的对象数组
aoColumns:[
{mData:render_engine},//< - wh使用内部对象
{mData:browser},
{mData:platform},
{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 variablehttp://live.datatables.net/utecax/edit#

Example trying to use array of objects with aaDatahttp://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而不是数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 00:07