【发布时间】:2014-01-26 15:56:19
【问题描述】:
我创建了一个 ASP.net MVC 应用程序并创建了一个 DataTable [DataTable.net],如下所示:
<table id="invoiceTable">
<thead>
<tr>
<th>Invoice ID</th>
<th>Date</th>
<th>Reciept Date</th>
<th>Category</th>
<th>Total Value</th>
<th>Invoice Ref</th>
<th>Client</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@{
foreach (FreeAgentApp.Models.CustomInvoice _invoice in ViewBag.Invoices)
{
<tr>
<td>@_invoice.InvoiceId</td>
<td>@_invoice.Date</td>
<td>@_invoice.RecpDate</td>
<td>@_invoice.Category</td>
<td>@_invoice.TotalValue</td>
<td>@_invoice.InvoiceRef</td>
<td>@_invoice.Client</td>
<td>@_invoice.Status</td>
</tr>
}
}
</tbody>
</table>
当使用javascript选择一行时,我可以从一行中获取信息,如下所示:
// Row data
$(document).ready(function () {
oTable = $('#invoiceTable').dataTable();
oTable.$('tr').click(function () {
var data = oTable.fnGetData(this);
alert(data);
// ... do something with the array / object of data for the row
});
});
变量数据将提供行中每个值的字符串,用逗号分隔,如下所示:
"000,26-01-14,27-01-14,001,1000,inv,something ltd,paid"
我想将所有这些值分开。请注意,这可以通过拆分逗号来完成,但是表中的值可以包含逗号。
如何分隔这个字符串?
【问题讨论】:
标签: javascript c# asp.net asp.net-mvc datatables