繁体   English   中英

将 Json 数据传递给 handsontable

[英]Passing Json data to handsontable

我正在尝试从我的数据库中获取数据并使用 Json 将其显示在 handsontable 中。 这是我到目前为止编写的代码。 谁能指导我如何解决这个问题。

        [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>

你有线

const container = document.getElementById('example');

但示例中提供了非 html。 所以可能你只需要添加

<div id="example"></div>

到您的 html 代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM