Javascript 在数据表中发送 JSON 对象 aaData 而不是数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14160483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending JSON Objects in DataTables aaData instead of arrays
提问by BillPull
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.
我在我的应用程序上使用 jquery DataTables 插件,到目前为止我对这个功能非常满意,尽管我想将数据传递给 aaData 属性略有不同。
currently it only seems to accept the javascript array as
目前它似乎只接受 javascript 数组作为
[
['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 ).
我希望能够使用对象而不是数组,因为它会更干净并帮助我扩展一些过滤我更容易做。我如何向它传递一个看起来像这样的 javascript 变量(不是通过 AJAX 加载)。
[
{'id':1,'status':0,'name': 'hello world'},
...,
...,
]
Example trying to use sAjaxSource with local variable http://live.datatables.net/utecax/edit#
尝试将 sAjaxSource 与局部变量一起使用的示例 http://live.datatables.net/utecax/edit#
Example trying to use array of objects with aaData http://live.datatables.net/iyavud/5/edit
尝试将对象数组与 aaData 一起使用的示例 http://live.datatables.net/iyavud/5/edit
回答by ?????
You can pass in the array of objects via aaData property, then use aoColumns property to define which column should recieve which data
您可以通过 aaData 属性传入对象数组,然后使用 aoColumns 属性来定义哪个列应该接收哪些数据
$('#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" }
]
});

