gpt4 book ai didi

javascript - 使用 jQuery MVC 将 SQL 表数据转换为 HTML 表

转载 作者:行者123 更新时间:2023-11-30 20:23:34 25 4
gpt4 key购买 nike

为此,我正在尝试将 SQL 表详细信息转换为 HTML 表,我所做的是创建了一个 Controller 、模型和 View 。我还创建了包含凭单编号和金额字段的 SQL 表。这是我在这里创建 Controller 的方式我已经引用了模型,模型演示

<HttpGet>
Function GetSalesDetail(invoiceId As String) As JsonResult
Dim listSalesDetail As List(Of Hashtable) = New ModelDemo().GetSalesDetail(invoiceId)
Return Json(listSalesDetail, JsonRequestBehavior.AllowGet)
End Function

模型演示代码由SQL连接组成

Public Function GetSalesDetail(invoiceId As String) As List(Of Hashtable)
Dim listSalesDetail As List(Of Hashtable) = New List(Of Hashtable)
Dim arraySalesDetail As Hashtable
'Dim arraySalesDetail As Dictionary(Of String, String) '**Associative array**'
Dim conn = New SqlConnection(connStringLocal)
conn.Open()
Using query = New SqlCommand("SELECT vchNum,productName,Qty,Price,Amount,total FROM BillDetails
WHERE vchNum='" & invoiceId & "'", conn)
Using resultSet = query.ExecuteReader
If resultSet.HasRows Then
While resultSet.Read()
'arraySalesDetail = New Dictionary(Of String, String)
arraySalesDetail = New Hashtable
arraySalesDetail.Add("vchNum", resultSet("vchNum"))
arraySalesDetail.Add("ProductName", resultSet("ProductName"))
arraySalesDetail.Add("Qty", resultSet("Qty"))
arraySalesDetail.Add("Price", resultSet("Price"))
arraySalesDetail.Add("Amount", resultSet("Amount"))
arraySalesDetail.Add("total", resultSet("total"))
listSalesDetail.Add(arraySalesDetail)
End While
End If
resultSet.Close()
'resultSet = Nothing
End Using
End Using
conn.Close()
Return listSalesDetail
End Function

document.load 函数由

$.get('@Url.Content("~")Home/GetSalesDetail', {
invoiceId: salesHeaderData.invoiceId
})
.done(function(salesDetailData) {
for (var j = 0; j < salesDetailData.length; j++) {
var input = {};
console.log("Loop for list details");
$('input[name="ProductName"]').val(salesDetailData.ProductName);
$('input[name="Qty"').val(salesDetailData.Qty);
$('input[name="Price"').val(salesDetailData.Price);
}
})

和索引html由

 <table id="detailTable">
<thead><tr><th>ProductName</th><th>Qty</th><th>Price</th></tr></thead>
<tbody>
<tr>
<td><input name="ProductName"></td>
<td><input name="Qty"></td>
<td><input name="Price">
</tr>
</tbody>
</table>

这就是我尝试的方式。任何人都可以帮助加载功能不工作吗?

最佳答案

如果可以删除输入,您可以这样做:

    var html = '';      
$.each(salesDetailData, function (i, item) {

html += '<tr><td>' + item.ProductName + '</td><td>' + item.Qty + '</td><td>' + item.Price + '</td></tr>';

})
$('tbody').append(html);

您的 html 将如下所示:

    <table id="detailTable">
<thead><tr><th>ProductName</th><th>Qty</th><th>Price</th></tr></thead>
<tbody>
</tbody>
</table>

关于javascript - 使用 jQuery MVC 将 SQL 表数据转换为 HTML 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51184445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com