我正在尝试为动态生成的html添加分页。我在Default.aspx页面中添加了这些脚本
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script>
<script type ="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<link rel ="stylesheet" type=" text/css" href=" https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
<div id = resultDiv></div>
该表格将出现在此div中。 在从Web服务获取JSON响应后,动态创建表
我的 JS 文件看起来像这样
$.ajax({
url: 'cannot mention',
method: 'get',
data: requestData,
dataType: 'json',
success: function (data) {
var ordersArray = data.orders;
var i;
var k;
var quantityArray;
var out = "<legend class='bluefont'><b><span id='info'>FOD</span></b></legend>"
out += "<table id ='tableresult' border='2px' style='font-size: 8pt '>";
out += "<tr><th> Order Date</th>";
for (i = 0; i < ordersArray.length; i++) {
out += "<td>" + ordersArray[i].orderDate + "</td>";
}
out += "</tr>";
out += "<tr><th>Delivery Date</th>";
for (i = 0; i < ordersArray.length; i++) {
out += "<td>" + ordersArray[i].deliveryDate + "</td>";
}
out += "</tr>";
out += "<tr><th>Quantity</th>";
for (i = 0; i < ordersArray.length; i++) {
quantityArray = ordersArray[i].order
for (k = 0; k < quantityArray.length ; k++){
out += "<td>" + quantityArray[k].quantity + "</td>";
}
}
out += "</tr>";
out += "</table>";
document.getElementById("resultDiv").innerHTML = out;
document.getElementById("tableresult").dataTable
它说dataTable不是一个功能。请帮忙
答案 0 :(得分:2)
你需要jQuery对象来初始化jQuery DataTables。例如:
[HttpPost]
public ActionResult Save(Option option)
{
var opt = StoreDatabase.Options.Find(option.OptionID);
if (opt != null)
{
StoreDatabase.Entry(opt).CurrentValues.SetValues(option);
StoreDatabase.SaveChanges();
}
return RedirectToAction("EditList", option.ProductID);
}