gpt4 book ai didi

javascript - 我无法使用 jquery 使用 Handsontable 加载数据

转载 作者:行者123 更新时间:2023-11-30 00:16:37 27 4
gpt4 key购买 nike

我正在使用 Django(在后端使用 Django Rest Framework)和 Front(使用 Jquery 的 django 模板)开发一个应用程序。我已经尝试在 Handsontable 库中加载信息,但是当我尝试加载时它显示了错误消息。

Uncaught Error: loadData only accepts array of objects or array of arrays (string given)

我的 json 是:

{
"description": "[{\"data\": \"CEA\", \"type\": \"text\"}, {\"data\": \"CROTAL\", \"type\": \"text\"}, {\"data\": \"NOMBRE\", \"type\": \"text\"}, {\"data\": \"D. NACIMIENTO\", \"type\": \"text\"}, {\"data\": \"D. PARTO\", \"type\": \"text\"}, {\"data\": \"NP\", \"type\": \"text\"}, {\"data\": \"D. ANALISIS\", \"type\": \"text\"}, {\"data\": \"NC\", \"type\": \"text\"}, {\"data\": \"LECHE\", \"type\": \"text\"}, {\"data\": \"%G\", \"type\": \"text\"}, {\"data\": \"%P\", \"type\": \"text\"}, {\"data\": \"RCS\", \"type\": \"text\"}, {\"data\": \"DIAS\", \"type\": \"text\"}, {\"data\": \"LE AC\", \"type\": \"text\"}, {\"data\": \"%G AC\", \"type\": \"text\"}, {\"data\": \"%P AC\", \"type\": \"text\"}]",
"typeset": 0,
"titles": "[\"CEA\", \"CROTAL\", \"NOMBRE\", \"D. NACIMIENTO\", \"D. PARTO\", \"NP\", \"D. ANALISIS\", \"NC\", \"LECHE\", \"%G\", \"%P\", \"RCS\", \"DIAS\", \"LE AC\", \"%G AC\", \"%P AC\"]",
"ren": 3,
"error": 0,
"producciones": "[{\"cea\": 2785658758, \"crotal\": \"ES025986548856\", \"nombre\": 8856, \"fchNaci\": \"None\", \"dparto\": \"2014-09-01 00:00:00\", \"np\": 2, \"danalisis\": \"2014-12-15 00:00:00\", \"nc\": 0.2, \"leche\": 32, \"pg\": 3.75, \"pp\": 3.27, \"rcs\": 201, \"dias\": 81, \"le_ac\": 2870, \"pgac\": 4.41, \"ppac\": 3.24}, {\"cea\": 2785658758, \"crotal\": 2785658758, \"nombre\": \"1111 MALU\", \"fchNaci\": \"None\", \"dparto\": \"2014-01-15 00:00:00\", \"np\": 3, \"danalisis\": \"2014-12-15 00:00:00\", \"nc\": 0.9, \"leche\": 36.5, \"pg\": 2.88, \"pp\": 3.28, \"rcs\": 21, \"dias\": 165, \"le_ac\": 11286, \"pgac\": 5.15, \"ppac\": 3.45}]",
"col": 13
}

我在 Jquery 中的函数是:

function processHandsontable(data) {
var hstSelctors = ["#gridxls", "#xlssal"];
var content = JSON.parse(data);
var $container;
if (content.error != 0) {
sweetAlert("Error", "No information", "error");
} else {
$container = $(hstSelctors[content.typeset]);
var datos = content.producciones;
$container.handsontable({
startRows: content.ren,
startCols: content.col,
colHeaders: content.titles,
columns: content.description,
data: datos
});
}
}

不知道哪里出错了

最佳答案

如错误消息所述,datos 应该是对象数组或数组数组。目前它是一个 json 对象。在 handsontable() 函数的选项中使用 json 数组作为 data。像这样更改 datos

  [{
"description": "[{\"data\": \"CEA\", \"type\": \"text\"}, {\"data\": \"CROTAL\", \"type\": \"text\"}, {\"data\": \"NOMBRE\", \"type\": \"text\"}, {\"data\": \"D. NACIMIENTO\", \"type\": \"text\"}, {\"data\": \"D. PARTO\", \"type\": \"text\"}, {\"data\": \"NP\", \"type\": \"text\"}, {\"data\": \"D. ANALISIS\", \"type\": \"text\"}, {\"data\": \"NC\", \"type\": \"text\"}, {\"data\": \"LECHE\", \"type\": \"text\"}, {\"data\": \"%G\", \"type\": \"text\"}, {\"data\": \"%P\", \"type\": \"text\"}, {\"data\": \"RCS\", \"type\": \"text\"}, {\"data\": \"DIAS\", \"type\": \"text\"}, {\"data\": \"LE AC\", \"type\": \"text\"}, {\"data\": \"%G AC\", \"type\": \"text\"}, {\"data\": \"%P AC\", \"type\": \"text\"}]",
"typeset": 0,
"titles": "[\"CEA\", \"CROTAL\", \"NOMBRE\", \"D. NACIMIENTO\", \"D. PARTO\", \"NP\", \"D. ANALISIS\", \"NC\", \"LECHE\", \"%G\", \"%P\", \"RCS\", \"DIAS\", \"LE AC\", \"%G AC\", \"%P AC\"]",
"ren": 3,
"error": 0,
"producciones": "[{\"cea\": 2785658758, \"crotal\": \"ES025986548856\", \"nombre\": 8856, \"fchNaci\": \"None\", \"dparto\": \"2014-09-01 00:00:00\", \"np\": 2, \"danalisis\": \"2014-12-15 00:00:00\", \"nc\": 0.2, \"leche\": 32, \"pg\": 3.75, \"pp\": 3.27, \"rcs\": 201, \"dias\": 81, \"le_ac\": 2870, \"pgac\": 4.41, \"ppac\": 3.24}, {\"cea\": 2785658758, \"crotal\": 2785658758, \"nombre\": \"1111 MALU\", \"fchNaci\": \"None\", \"dparto\": \"2014-01-15 00:00:00\", \"np\": 3, \"danalisis\": \"2014-12-15 00:00:00\", \"nc\": 0.9, \"leche\": 36.5, \"pg\": 2.88, \"pp\": 3.28, \"rcs\": 21, \"dias\": 165, \"le_ac\": 11286, \"pgac\": 5.15, \"ppac\": 3.45}]",
"col": 13
}]

关于javascript - 我无法使用 jquery 使用 Handsontable 加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34469626/

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