我一直在尝试使用JQuery和Datatables.net将数据表添加到我的站点。 我已经尝试过stackoverflow和Datatables.net的许多解决方案,但无法弄清楚。 奇怪的是,由于表页脚中显示的条目数正确,因此它确实加载了Json数据。关于该问题可能有什么指示?
据我所知这是有效的Json,这是我方法返回的Json
{"data":[{"materialEfficiency":10,"timeEfficiency":20,"imageUrl":"https://imageserver.eveonline.com/Type/2184_64.png","blueprintName":"Hammerhead I Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":23581.52},{"materialEfficiency":10,"timeEfficiency":20,"imageUrl":"https://imageserver.eveonline.com/Type/1145_64.png","blueprintName":"Antimatter Charge M Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":3598.87},{"materialEfficiency":10,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/2445_64.png","blueprintName":"Ogre I Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":21757.32},{"materialEfficiency":10,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/2477_64.png","blueprintName":"Berserker I Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":38405.71},{"materialEfficiency":10,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/2194_64.png","blueprintName":"Praetor I Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":61750.2},{"materialEfficiency":10,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/1214_64.png","blueprintName":"Wasp I Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":40214.46},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/811_64.png","blueprintName":"Scourge Light Missile Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":560.32},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/812_64.png","blueprintName":"Inferno Light Missile Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":549.0},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/1130_64.png","blueprintName":"Iron Charge S Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":205.5},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/814_64.png","blueprintName":"Nova Light Missile Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":540.46},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/810_64.png","blueprintName":"Scourge Heavy Missile Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":4126.82},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/1134_64.png","blueprintName":"Thorium Charge S Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":555.91},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/901_64.png","blueprintName":"Phased Plasma L Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":10641.8},{"materialEfficiency":0,"timeEfficiency":0,"imageUrl":"https://imageserver.eveonline.com/Type/1140_64.png","blueprintName":"Iridium Charge M Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":1353.82},{"materialEfficiency":10,"timeEfficiency":20,"imageUrl":"https://imageserver.eveonline.com/Type/1145_64.png","blueprintName":"Antimatter Charge M Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":3598.87}]}
这是我的JQuery
$(function () {
$('.js-exportable').DataTable({
"ajax": {
"url": "Manufacturing/LoadData",
"data": ""
},
"columns": [
{ "data": "ImageUrl" },
{ "data": "MaterialEfficiency" },
{ "data": "TimeEfficiency" },
{ "data": "BlueprintName" },
{ "data": "Location" },
{ "data": "ManufactureCost" }
]
});
});
,这就是我在视图中创建表格的方式
<div class="row clearfix" style="margin-top:20px;">
<div class="col-lg-12">
<div class="card">
<div class="header">
<h2>Blueprints<small>Current blueprints owned by character</small></h2>
<ul class="header-dropdown dropdown">
<li><a href="javascript:void(0);" class="full-screen"><i class="icon-frame"></i></a></li>
</ul>
</div>
<div class="body">
<div class="table-responsive">
<table class="table table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
<th>Location</th>
<th>Material Efficiency</th>
<th>Time Efficiency</th>
<th>Estimated Manufacture Cost</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
我的朋友。如您所见,数据响应:
{"materialEfficiency":10,"timeEfficiency":20,"imageUrl":"https://imageserver.eveonline.com/Type/2184_64.png","blueprintName":"Hammerhead I Blueprint","location":"Sobaseki X - Moon 12 - Propel Dynamics Factory","manufactureCost":23581.52}
但是您定义了这样的列:
"columns": [
{ "data": "ImageUrl" },
{ "data": "MaterialEfficiency" },
{ "data": "TimeEfficiency" },
{ "data": "BlueprintName" },
{ "data": "Location" },
{ "data": "ManufactureCost" }
]
因此,您需要返回名称与Datatables配置匹配的对象,如下所示:
"columns": [
{ "data": "imageUrl" },
{ "data": "materialEfficiency" },
{ "data": "timeEfficiency" },
{ "data": "blueprintName" },
{ "data": "location" },
{ "data": "manufactureCost" }
]
希望有帮助,我的朋友:))