cod*_*boy 20 jquery json datatables
我有一个像这样格式化的本地JSON对象:
[{
"id": "58",
"country_code": "UK",
"title": "Legal Director",
"pubdate": "2012-03-08 00:00:00",
"url": "http://..."
},{
"id": "59",
"country_code": "UK",
"title": "Solutions Architect,",
"pubdate": "2012-02-23 00:00:00",
"url": "http://..."
},{
// ....more of the same......
}]
Run Code Online (Sandbox Code Playgroud)
我想设置此作为一个jQuery的数据源的数据表,并尝试这样的:
testdata = '{{ jobsJSON | raw }}'; //twig template tag
console.log(testdata);
$('#test').dataTable({
"aoData": testdata,
"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "country_code" },
{ "mDataProp": "title" },
{ "mDataProp": "pubdate" },
{ "mDataProp": "url" }
]
});
Run Code Online (Sandbox Code Playgroud)
DataTables插件加载并尝试绘制表,但会显示错误"表格中没有可用数据"
我没有进行AJAX调用,只想从本地JS变量访问JSON对象.
Ror*_*san 41
提供您自己的数据的属性aaData不是aoData:
testdata = [{"id":"58",...}]; // local object
$('#test').dataTable({
"aaData": testdata,
"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "country_code" },
{ "mDataProp": "title" },
{ "mDataProp": "pubdate" },
{ "mDataProp": "url" }
]
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57962 次 |
| 最近记录: |