cuốn sách gpt4 ai đã làm

DataTable.js - Đối với một số tập dữ liệu được truyền qua lệnh gọi Ajax, Không có dữ liệu sẽ được hiển thị trong

In lại Tác giả: Walker 123 更新时间:2023-11-28 17:05:49 28 4
mua khóa gpt4 Nike

对于某些数据集,数据表中不显示任何数据 - 仅显示列标题或列标签。即使页面上的代码没有更改,也会发生这种情况。有问题的数据在浏览器开发工具 Console.logs 中正确显示。

如下所示,DataSet 的 JSON 可以在 HTML 页面上正确显示/呈现。


{"data_json":

{"columns": ["customer_id", "col_1_int", "col_2_int", "col_3_float", "col_4_int", "col_5_str"],

"data":
[[1, "349", "349", "355.6677", "112", "hello am a string "],
[2, "404", "404", "355.6677", "167", "hello am a string "],
[3, "459", "459", "355.6677", "222", "hello am a string "],

如下所示的 JSON 数据集在 HTML 页面上无法正确显示。

{"data_json": 

{"columns": ["rats_mice", "var_rats1", "var_rats2"],

"data":
[["CAT_C", 6.0, 69.0],
["CAT_A", 3.0, 34.0],
["CAT_B", 4.0, 37.0],
["CAT_B", 5.0, 63.0],
["CAT_C", 5.5, 88.0],

DataTables 的 JS 代码如下所示:-





var myUrl = "{% url 'django_url_withJSON' %}"
var dataSet;
var my_columns = [];

$(document).ready(function(){
$.ajax({
url: myUrl,
gõ: 'NHẬN',
dataType: 'json',
success: function(dict_json_from_py) {
console.log("-----dict_json_from_py--Data displays fine in Console--")
console.log(dict_json_from_py)
var dataSet = dict_json_from_py.data_json.columns;
//console.log(dataSet)
$.each(dataSet, function( key, value ) {
var my_item = {};
my_item.data = key;
my_item.title = value;
console.log(my_item.data)
console.log(my_item.title)
my_columns.push(my_item);
console.log(my_columns)
return my_columns
});

assignToEventsColumns(my_columns,dict_json_from_py);
}, // Close - success:
}) // Close - "ajax":

function assignToEventsColumns(my_columns,dict_json_from_py) {

var table = $('#example').DataTable({
"bAutoWidth" : false, //bAutoWidth -- b == BOOLEAN
"serverSide": false, //
"aaData": dict_json_from_py.data_json.data,
"columns" : my_columns,
})
}
});



除了检查 JSON 结构的一致性之外 - 我不确定还能做什么。

câu trả lời hay nhất

我刚刚检查了您的代码,对我来说似乎很好。只需确保 JSON 格式正确即可。希望这个jsfiddle会帮助你的。

{
"data_json": {
"columns": [
"customer_id", "col_1_int", "col_2_int", "col_3_float", "col_4_int", "col_5_str"
],
"data":
[
[1, "349", "349", "355.6677", "112", "hello am a string "],
[2, "404", "404", "355.6677", "167", "hello am a string "],
[3, "459", "459", "355.6677", "222", "hello am a string "]
]
}
}

关于javascript - DataTable.js - 对于通过 Ajax 调用传入的某些数据集, 内不会显示任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55905593/

28 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress