我正在尝试填写用户帐户网页上的表格。具体为交易历史数据表。出于某种原因,我得到一个表“未找到记录”的表,只有在此之后我才能在底部列出所有交易(所有交易都与页面集上的数字无关)。当然,所有控件(搜索,页面上的项目)都不起作用。我做错了什么?
以下是我从Web服务收到的JSON对象:
{"success":true,"balance":4284.77,"transactions":[{"transaction_id":"664f9abf-7dd7-40c5-af67-e90fb0a1c699","create_date":"2016-05-27T16:57:24.955Z","type":"credit","comment":"Пополнение баланса","value":2500},{"transaction_id":"cc8b538a-5164-405f-acc6-0a2d5c4b2bc2","create_date":"2016-05-05T10:32:11.377Z","type":"transfer","comment":null,"value":1,"recipient_type":"user","recipient":{"user_id":"198c5f7d-c32c-4843-8e1f-60f172fbe0c3","name":"Andrey Skvortsov"}},{"transaction_id":"dc376235-b7a0-4f53-9b0a-ceb245dff7e9","create_date":"2016-05-05T10:31:50.518Z","type":"transfer","comment":null,"value":25,"recipient_type":"user","recipient":{"user_id":"198c5f7d-c32c-4843-8e1f-60f172fbe0c3","name":"Andrey Skvortsov"}},{"transaction_id":"81052f18-7cb5-49e8-ac24-82c245df2889","create_date":"2016-05-05T10:21:12.529Z","type":"transfer","comment":null,"value":15,"recipient_type":"user","recipient":{"user_id":"198c5f7d-c32c-4843-8e1f-60f172fbe0c3","name":"Andrey Skvortsov"}},{"transaction_id":"8b0cf4a0-86dd-4f31-8a73-5562a7959486","create_date":"2016-05-05T10:12:14.647Z","type":"transfer","comment":null,"value":2000,"recipient_type":"user","recipient":{"user_id":"198c5f7d-c32c-4843-8e1f-60f172fbe0c3","name":"Andrey Skvortsov"}},{"transaction_id":"4aac064c-cb04-458c-a274-56b06933b373","create_date":"2016-05-05T10:11:25.766Z","type":"transfer","comment":null,"value":300,"recipient_type":"user","recipient":{"user_id":"198c5f7d-c32c-4843-8e1f-60f172fbe0c3","name":"Andrey Skvortsov"}},{"transaction_id":"e2d9dab6-aa18-499f-8dfa-d0cb07d65ff4","create_date":"2016-05-05T10:10:00.907Z","type":"credit","comment":"Пополнение баланса","value":2500},{"transaction_id":"c77381bb-a36d-4256-ab61-b878699aeaa7","create_date":"2016-05-03T19:44:16.266Z","type":"transfer","comment":null,"value":1570.99,"recipient_type":"user","recipient":{"user_id":"26e9e9eb-0a33-431e-9f12-2a4e02305a4c","name":"Cafe Tony"}},{"transaction_id":"711bd2f6-0391-42a2-999a-27bdb562f373","create_date":"2016-04-17T10:03:37.272Z","type":"credit","comment":"Пополнение баланса","value":200},{"transaction_id":"99f15c44-ec84-4e33-b09f-c7215ab00ff0","create_date":"2016-04-11T05:38:18.038Z","type":"transfer","comment":null,"value":2,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"2f0eeede-6859-49a1-872b-00b237042cbf","create_date":"2016-04-11T05:37:56.424Z","type":"transfer","comment":null,"value":0.05,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"53d04098-4f84-4a19-a8c6-37dda8ada97a","create_date":"2016-04-11T05:37:28.971Z","type":"transfer","comment":null,"value":35.99,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"550facce-78e1-4742-9751-92c7c1eb834e","create_date":"2016-04-11T05:37:09.891Z","type":"transfer","comment":null,"value":11,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"308b18d2-e97b-41e3-8aa0-1da771f44b3b","create_date":"2016-04-11T05:25:32.269Z","type":"transfer","comment":null,"value":17.99,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"35916cff-b1d3-43cc-aec2-06d947e9572b","create_date":"2016-03-30T05:05:57.443Z","type":"transfer","comment":null,"value":12,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"86bd5fbc-3f90-4a6f-81a8-00870846a6ed","create_date":"2016-03-30T05:04:58.602Z","type":"transfer","comment":null,"value":28,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"98f6c6ea-1cc5-4884-bbd1-cc1f47b88255","create_date":"2016-03-17T04:46:10.528Z","type":"transfer","comment":null,"value":1.99,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"b09b5457-9157-4fdb-8850-f86233b41822","create_date":"2016-03-17T04:45:48.512Z","type":"transfer","comment":null,"value":77.5,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"73469083-4316-4a20-9c15-df81a4b9e640","create_date":"2016-03-16T08:25:56.714Z","type":"transfer","comment":null,"value":99,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"d8a0800f-6ef7-485a-a720-3cd4cb885bb1","create_date":"2016-03-16T08:25:35.343Z","type":"transfer","comment":null,"value":22,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"e215a49d-c658-42b0-a376-367982115ad6","create_date":"2016-03-16T08:24:33.473Z","type":"transfer","comment":null,"value":17,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"3bfcd5d0-2ff8-4023-87e8-ad089e364bcb","create_date":"2016-03-15T08:17:28.768Z","type":"transfer","comment":null,"value":25,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"0b3d7c8d-c076-47d9-b8e6-e11551f8f8c6","create_date":"2016-03-15T08:17:09.044Z","type":"transfer","comment":null,"value":23.85,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"8ade9c0d-5278-4be5-b07b-ae7c15ad2254","create_date":"2016-03-15T08:16:45.815Z","type":"transfer","comment":null,"value":2,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"3cbaae0b-7277-400d-b47d-7ba339a99bb0","create_date":"2016-03-12T05:00:58.210Z","type":"transfer","comment":null,"value":25,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"0cc85dc7-cbf6-4a2c-8c67-13e12903e99c","create_date":"2016-03-03T17:21:49.639Z","type":"transfer","comment":null,"value":113.99,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"946293ab-808f-4a0d-a237-ee3cb7902291","create_date":"2016-03-03T17:21:18.177Z","type":"transfer","comment":null,"value":10,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"e45a333a-864d-4283-acf1-1ab6531eb951","create_date":"2016-02-24T05:43:12.705Z","type":"transfer","comment":null,"value":1.88,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"0eab01c1-2fd2-44a9-9c11-986993355c4b","create_date":"2016-02-24T05:42:48.497Z","type":"transfer","comment":null,"value":45,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"bbe7b97e-cdf8-4161-bc72-43f2a5a1a855","create_date":"2016-02-24T05:40:46.571Z","type":"transfer","comment":null,"value":13,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"2a63db37-dd08-43b2-b953-170441f8b894","create_date":"2016-02-24T05:26:46.905Z","type":"transfer","comment":null,"value":111,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"cfba7638-47d5-4d98-b5ce-92458136b376","create_date":"2016-02-24T05:26:15.972Z","type":"transfer","comment":null,"value":170,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"ea417b5b-0158-480d-88be-20b351c5d1aa","create_date":"2016-02-24T05:23:00.927Z","type":"transfer","comment":null,"value":250,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"af5a7d72-97a5-4b71-9b33-fd607803d16c","create_date":"2016-02-24T05:16:14.957Z","type":"transfer","comment":null,"value":700,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"fef84bb4-76cc-4fe3-8902-a26a1f52e714","create_date":"2016-02-24T05:15:27.464Z","type":"transfer","comment":null,"value":150,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"e3ed2627-3da8-4608-8537-6f3232e5da95","create_date":"2016-02-24T05:14:43.094Z","type":"transfer","comment":null,"value":12.5,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"ad8d8eab-dc58-4a61-b8e4-5865c4e58d1f","create_date":"2016-02-24T05:14:04.045Z","type":"transfer","comment":null,"value":17.02,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"59b110a5-e53e-4e8c-b73c-6380e9282e0b","create_date":"2016-02-24T05:13:21.742Z","type":"transfer","comment":null,"value":1.99,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"4a2cb275-fb99-457e-8ded-649c2768a644","create_date":"2016-02-24T05:12:11.643Z","type":"transfer","comment":null,"value":20.85,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"bc0072a8-b9c6-43ca-b257-2f47bb05af09","create_date":"2016-02-24T05:11:32.316Z","type":"transfer","comment":null,"value":11.11,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"734a5d9a-93e3-4583-b741-c9ce64c6a233","create_date":"2016-02-24T05:08:49.539Z","type":"transfer","comment":null,"value":20.9,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"6a7de36e-5c3e-466b-8f11-863d7b8671c0","create_date":"2016-02-24T05:02:56.448Z","type":"transfer","comment":null,"value":0.99,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"cbe85511-8ddc-48fc-8f9a-f81f2df33a5f","create_date":"2016-02-22T06:56:38.784Z","type":"transfer","comment":null,"value":1.99,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"d6cc8177-f2b0-4ee8-9f99-f4054738afaa","create_date":"2016-02-16T06:30:29.115Z","type":"transfer","comment":null,"value":21.99,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"affd73f6-2d64-460b-a48d-3a3822614148","create_date":"2016-02-16T06:29:13.200Z","type":"transfer","comment":null,"value":7,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"5f8ddc50-0496-4a89-9315-a6d6f25f62fa","create_date":"2016-02-16T06:20:16.691Z","type":"transfer","comment":null,"value":1,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"57518776-1082-4c0e-a299-f953bde20eef","create_date":"2016-02-16T06:04:02.625Z","type":"transfer","comment":null,"value":22,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"2ba8eb08-4e3b-4a98-be32-280804cca83e","create_date":"2016-01-30T18:01:57.741Z","type":"transfer","comment":null,"value":10,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"110a15fd-90a7-4c40-b3df-18f8049c2fcc","create_date":"2016-01-30T18:01:30.916Z","type":"transfer","comment":null,"value":2,"recipient_type":"user","recipient":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}},{"transaction_id":"bf05a60d-b0e8-4837-b7f0-97d597b2026d","create_date":"2016-01-30T17:58:26.906Z","type":"transfer","comment":null,"value":22,"sender_type":"user","sender":{"user_id":"7a437ed9-054b-48e4-b43f-a654b733b000","name":"Tom Ford"}}]}
这是来自th.ejs文件的片段(标题翻译为英文):
<table id="table-1" class="datatable table table-striped table-bordered">
<thead>
<tr>
<th>User</th>
<th>Date and Time</th>
<th>Amount</th>
<th>Transaction #</th>
</tr>
</thead>
</table>
...
<script src="js/plugins/dataTables/jquery.datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.getJSON("/transactions", function (json) {
var tr;
for (var i = 0; i < json.transactions.length; i++) {
tr = $('<tr/>');
if (json.transactions[i].type=='credit') {
tr.append("<td>" + "Пополнение счета" + "</td>");
} else if (json.transactions[i].recipient_type=='user') {
tr.append("<td>" + json.transactions[i].recipient.name + "</td>");
} else {
tr.append("<td>" + json.transactions[i].sender.name + "</td>");
}
var timedate = moment(json.transactions[i].create_date).format('dd, DD MMMM YYYY, h:mm:ss');
tr.append("<td>" + timedate + "</td>");
if (json.transactions[i].recipient_type=='user') {
var amount = numeral(json.transactions[i].value).format('0,0.00 $');
tr.append("<td>" + "- "+ amount + "</td>");
} else {
var amount = numeral(json.transactions[i].value).format('0,0.00 $');
tr.append("<td>" + amount + "</td>");
}
tr.append("<td>" + json.transactions[i].transaction_id + "</td>");
$('#table-1').append(tr);
}
});
});
</script>
答案 0 :(得分:0)
理想情况下,您应该使用指定here的DataTables ajax数据源,以使用ajax将数据加载到表中。
对于您所做的事情,您可以尝试销毁并重新初始化DataTable.So将所有行附加到该表后尝试执行此操作。
php_pdo_sqlsrv_56_ts.dll
答案 1 :(得分:0)
在追加所有行之后,您需要再次初始化表格。
$('#table-1').DataTable();
可能必须销毁旧的
$('#table-1').destroy().DataTable();