Javascript 将Json数据传递给handsontable
我正在尝试从数据库中获取数据,并使用Json将其显示在handsontable中。这是我到目前为止编写的代码。有谁能指导我如何解决这个问题吗Javascript 将Json数据传递给handsontable,javascript,c#,asp.net,json.net,handsontable,Javascript,C#,Asp.net,Json.net,Handsontable,我正在尝试从数据库中获取数据,并使用Json将其显示在handsontable中。这是我到目前为止编写的代码。有谁能指导我如何解决这个问题吗 [HttpGet] public JsonResult Index() { IEnumerable<SupplierTypeDto> supplierType = new List<SupplierTypeDto>(); var apiR
[HttpGet]
public JsonResult Index()
{
IEnumerable<SupplierTypeDto> supplierType = new List<SupplierTypeDto>();
var apiResponse = Post<List<SupplierTypeDto>>("api/SupplierType/SuppliersType", null);
if (apiResponse != null)
{
if (apiResponse.Success)
{
supplierType = apiResponse.Data;
// ShowSuccessMesage(string.Format(ResponseMessages.DATA_Load_Success, "Customers"));
}
}
else
{
ShowErrorMesage(ResponseMessages.API_NoResponse);
}
return Json(supplierType,JsonRequestBehavior.AllowGet);
}
The code added below has data part and I want that data from Json so I can show it in Index file.
<script>
const data = [
['', 'Tesla', 'Volvo', 'Toyota', 'Ford'],
['2019', 10, 11, 12, 13],
['2020', 20, 11, 14, 13],
['2021', 30, 15, 12, 13]
];
const container = document.getElementById('example');
const hot = new Handsontable(container, {
data: data,
rowHeaders: true,
licenseKey: 'non-commercial-and-evaluation',
colHeaders: true
});
</script>
[HttpGet]
公共JsonResult索引()
{
IEnumerable supplierType=新列表();
var apiResponse=Post(“api/供应商类型/供应商类型”,null);
如果(apiResponse!=null)
{
如果(apiResponse.Success)
{
供应商类型=apiResponse.Data;
//ShowSuccessMessage(string.Format(ResponseMessages.DATA_Load_Success,“客户”));
}
}
其他的
{
淋浴服务(响应消息,API_NoResponse);
}
返回Json(supplierType,JsonRequestBehavior.AllowGet);
}
下面添加的代码包含数据部分,我希望这些数据来自Json,以便在索引文件中显示。
常数数据=[
[''‘特斯拉’、‘沃尔沃’、‘丰田’、‘福特’,
['2019', 10, 11, 12, 13],
['2020', 20, 11, 14, 13],
['2021', 30, 15, 12, 13]
];
const container=document.getElementById('example');
const hot=新的手持设备(容器、{
数据:数据,
行标题:对,
许可证密钥:“非商业和评估”,
colHeaders:对
});
您有一行
const container=document.getElementById('example')
但示例中提供了非html。所以你可能只需要加上
在您的html代码中我已将该div添加到我的html代码中,它正在显示数组数据,但问题是我需要的数据是通过Json从数据库中获取的,因此我可以将其传递给handsontable。上面的数据数组只是一个示例。