XHR响应中不必要的逗号最终出现在表格的单元格中 [英] Unwanted comma in XHR response ending up in table's cells
本文介绍了XHR响应中不必要的逗号最终出现在表格的单元格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XHR响应,看起来像这样:
I have an XHR response that looks something like this:
[
[
"e33222",
"1730-06-27",
"Lewis Morris",
[
"Edward Wynne; ",
"William Bulkeley"
]
], [...]
]
它用于填充表
var table = $('#mainTable').DataTable()
table.rows.add(result)
table.draw();
除了在每个后续子项的开头添加一个令人讨厌的逗号(或者更好的是,在每个具有子项的第一个子项的末尾添加逗号,请参见"Edward Wynne;", 威廉·伯克利").
It all works great, except for an annoying comma added at the beginning of every subsequent sub-item (or, better, at the end of every first sub-item which has a following one, see "Edward Wynne; ", "William Bulkeley").
最终结果是,在与我得到的数据相对应的单元格中:
The end result is that in the cell corresponding to that data I get:
William Morris; ,Richard Morris
有什么办法获取:
William Morris; Richard Morris
?
推荐答案
因此,请先遍历数据,然后再将其设置在数据表中并格式化数据,使其不是数组.
So loop over the data before you set it in the datatable and format the data so it is not an array.
var results = [
[
"e33222",
"1730-06-27",
"Lewis Morris",
[
"Edward Wynne; ",
"William Bulkeley"
]
],
[
"22222",
"2222-06-27",
"foooo Mooooo",
[
"foo bar; ",
"foo baz"
]
],
]
results.forEach(function (record) {
record[3] = record[3].join('')
})
console.log(results);
这篇关于XHR响应中不必要的逗号最终出现在表格的单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文