I am using data tables and trying to popular a table with data.
我正在使用数据表并尝试使用数据表。
The data I have looks like this:
我的数据看起来像这样:
<table id="mytable" class="display" width="100%"></table>
{
"users": [
{
"id": "6700",
"user": {
"firstName": "somename"
},
"Count": 0
}
]
}
So this is what I've done:
所以这就是我所做的:
var dataSet = {
"users": [
{
"id": "6700",
"user": {
"firstName": "somename"
},
"Count": 0
}
]
};
jQuery('#mytable').DataTable( {
data: dataSet,
columns: [
{ "users": "id" }
]
});
I'm am not getting any errors but the data is not inserted either.
我没有收到任何错误,但也没有插入数据。
What I'm I doing wrong here?
我在这里做错了什么?
1 个解决方案
#1
2
In data
option you need to provide variable that contains array of objects (dataSet.users
). Also in columns.data
option you need to define property within each object in the array (id
).
在数据选项中,您需要提供包含对象数组的变量(dataSet.users)。同样在columns.data选项中,您需要在数组(id)中的每个对象中定义属性。
Corrected code is shown below.
更正后的代码如下所示。
jQuery('#mytable').DataTable( {
"data": dataSet.users,
"columns": [
{ "data": "id", "title": "ID" }
]
});
See this example for demonstration.
请参阅此示例以进行演示。
#1
2
In data
option you need to provide variable that contains array of objects (dataSet.users
). Also in columns.data
option you need to define property within each object in the array (id
).
在数据选项中,您需要提供包含对象数组的变量(dataSet.users)。同样在columns.data选项中,您需要在数组(id)中的每个对象中定义属性。
Corrected code is shown below.
更正后的代码如下所示。
jQuery('#mytable').DataTable( {
"data": dataSet.users,
"columns": [
{ "data": "id", "title": "ID" }
]
});
See this example for demonstration.
请参阅此示例以进行演示。