将 json 数组转换为 aadata 格式
我当前的数组格式没有被数据表 aaData 格式解释为传递列值:
{
"aaData": [
{
"startDate": "09/08/2010 12:00:00 AM",
"endDate": "13/08/2010 12:00:00 AM",
"runDate": "16/08/2010 12:00:00 AM",
"clientId": "40272",
"clientType": "C",
"plannerName": "Adrian Mcfly",
"plannerRegion": "s1",
"contact": "Vera chaniqua",
"email": " ",
"interviewDate": "09/08/2010 12:00:00 AM"
},
]
}
如何删除列 id 并仅显示值,以便数据表可以将其作为 ajax 调用读取?
my currrent array format is not being interpreted by datatables aaData format as im passing column values:
{
"aaData": [
{
"startDate": "09/08/2010 12:00:00 AM",
"endDate": "13/08/2010 12:00:00 AM",
"runDate": "16/08/2010 12:00:00 AM",
"clientId": "40272",
"clientType": "C",
"plannerName": "Adrian Mcfly",
"plannerRegion": "s1",
"contact": "Vera chaniqua",
"email": " ",
"interviewDate": "09/08/2010 12:00:00 AM"
},
]
}
how do i remove the column id and display just the values so that i can be read by datatables as a ajax call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑 2012 年 8 月 29 日
从 1.9 开始,您可以禁止必须拥有根 JSON 属性。
这可能是大多数 JSON 序列化程序所得到的结果。
或者自定义它
在datatables 1.8中你可以像这样格式化你的json:
并在你的datatable属性中添加这个
EDIT 8/29/2012
As of 1.9 you can disable having to have a root JSON property.
This is likely what you will get with most JSON serializers.
Or customize it
In datatables 1.8 you can format your json like this:
And in your datatable properties add this
好吧,基本上你所得到的是对象数组的JSON表示(具有属性startDate,endDate,...) ,但您需要的是一个由字符串组成的数组数组。
我假设您正在进行服务器端处理,因此如果您不想更改服务器代码,您可以在获取过程的中间修改数据,然后再将其提供给数据表的回调。
接下来我要做的只是遍历获取的数据中的每个对象并创建值数组:
} );
希望它有效!
Well, basically what you've got there is a JSON representation of an array of objects (with properties startDate, endDate, ...), but what you need is an array of arrays of strings.
I'm assuming you are doing server-side processing, so if you don't want to change the server code, you can get just in the middle of the fetching process and modify the data right before giving it to the callback of datatables.
What I do next is just going through each object in the fetched data and create the array of values:
} );
Hope it works!
尝试使用方括号而不是左/右大括号 { 和 }。有关详细信息,请参阅我对此问题的回答:datatables and jsonformatting error with php
Try using square brackets instead of opening/closing curly braces { and }. For details, see my answer to this question: datatables and json formatting error with php