我正在尝试从数据库中获取数据,并使用Json将其显示在handontable中。这是我到目前为止编写的代码。谁能指导我解决该问题的方法。
[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>
您有行
常量容器= document.getElementById('example');
但示例中提供了非html。所以可能您只需要添加
<div id="example"></div>
到您的html代码