简体   繁体   English

如何使用jQuery将PHP中的数据加载到Handsontable?

[英]How to load data from PHP to Handsontable with jQuery?

I am using Handsontable to display data but I can't load the data that was returned from PHP. 我正在使用Handsontable来显示数据,但无法加载从PHP返回的数据。

Here is my jQuery code: 这是我的jQuery代码:

$("#handsontable").on('shown.bs.modal', function () {
      var container = document.getElementById('existdata');
      var hot = new Handsontable(container, {
          minSpareRows: 1,
          height: '380',
          rowHeaders: true,
          colHeaders: ['col1','col2','col3','col4','col5'],
          contextMenu: false,
          manualColumnResize: true,
          colWidths:[100,100,100,50,450]
      });
});
$(document).on('click','#btn',function(){
    var as = $('input[name="assign"]:checked').val();
    var data = $('#sample').attr('data-file');
    $.post('script/sample.php',{action:'sample',data:data,as:as},function(chk){
            $("#handsontable").modal("show");
            var d = ["","","","",JSON.parse(chk)];
            console.log(JSON.stringify(d))
            $('#existdata').handsontable('loadData', d);
    });
});

Here is the data that PHP returned: 这是PHP返回的数据:

["","","","",["TOR-038-7459_XCODE_Conforming_SCC_Proxy.wmv"]]

I use console.log(JSON.stringify(d)) to know what my d looks like. 我使用console.log(JSON.stringify(d))知道我的d是什么样子。

I just found out the root of my problem. 我才发现问题的根源。 The problem is the data that AJAX received from my PHP code. 问题是AJAX从我的PHP代码接收到的数据。 The proper data should be [["","","","","TOR-038-7459_XCODE_Conforming_SCC_Proxy.wmv"]] and not ["","","","",["TOR-038-7459_XCODE_Conforming_SCC_Proxy.wmv"]] . 正确的数据应该是[["","","","","TOR-038-7459_XCODE_Conforming_SCC_Proxy.wmv"]]而不是["","","","",["TOR-038-7459_XCODE_Conforming_SCC_Proxy.wmv"]]

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

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