我有一个 HTML 表:
<table id="tableOrderDetail" class="table-striped table-bordered" style="align: center; width: 100%;">
<thead>
<tr>
<th width="5%">Sr. No.</th>
<th width="25%">Product Name</th>
<th width="12%" class="center">No Of Carton</th>
<th width="12%" class="center">Quantity</th>
<th width="12%" class="center">Original Price</th>
<th width="12%" class="center">Order Price</th>
<th width="10%" class="center">Discount</th>
<th width="12%" class="center">Total Price</th>
</tr>
</thead>
<tbody>
<tr>
<td width="25%" class="ProductName"></td>
<td width="12%" class="NoOfCarton"></td>
<td width="12%" class="ProductQuantity"></td>
<td width="12%" class="OriginalPrice"></td>
<td width="12%" class="OrderPrice"></td>
<td width="10%" class="Discount"></td>
<td width="12%" class="TotalPrice"></td>
</tr>
</tbody>
现在我必须将所有数据附加到表中,我尝试如下:
$.ajax({
type: "POST",
url: "../handlers/DisplaySpecificOrderDetail.ashx?OrderId=" + Orderid, //+ "tk=" + Date.toLocaleTimeString()
data: "{ OrderId: " + Orderid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",
success: function (data) {
$("#tableOrderDetail tbody").find("tr:gt(0)").remove();
$.each(data, function (i, v) {
if (i == 0) {
//setting the data in first row itself
setDataOnRow($("#tableOrderDetail tbody").find("tr").first(), v);
} else {
//clonning the first row and setting data over it and then appending in tbody
var clonnedRow = $($("#tableOrderDetail tbody").find("tr").first()).clone();
setDataOnRow(clonnedRow, v);
$("#tableOrderDetail tbody").append(clonnedRow);
}
});
});
function setDataOnRow(rowObject, v) {
// debugger
$(rowObject).find(".ProductName").html(v.ProductName);
$(rowObject).find(".NoOfCarton").html(v.NoOfCarton);
$(rowObject).find(".ProductQuantity").html(v.ProductQuantity);
$(rowObject).find(".OriginalPrice").html(v.OriginalPrice);
$(rowObject).find(".OrderPrice").html(v.OrderPrice);
$(rowObject).find(".Discount").html(v.Discount);
$(rowObject).find(".TotalPrice").html(v.TotalPrice);
}
至此,数据已成功绑定到表中。
但对于多个记录,它只能获取最后一条记录。(覆盖)
如何将所有行与表绑定?
EDIT 1:
I used .append()
但它给了我一行中的两条记录..我怎样才能将它分开在不同的行中?
EDIT 2:这是我的处理程序:
public void ProcessRequest(HttpContext context)
{
try
{
context.Response.ContentType = "application/octet-stream";
long OrderId;
Result res = new Result();
long.TryParse(context.Request.QueryString["OrderId"].ToString(), out OrderId);
JavaScriptSerializer TheSerializer = new JavaScriptSerializer();
SpecificOrderDetailManagement specificordMgr = new SpecificOrderDetailManagement();
res = specificordMgr.GetOrderDetailOrderID(OrderId);
context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(res.ListObject));
}
catch (Exception ex)
{
throw ex;
}
}
Edit 3: Screen