1
我正試圖在handontable中加載數據。Handsontable - 表未呈現
HTML文件是很基本的: 只是一個表和一個按鈕加載由PHP腳本發送的數據(名爲actions.php):
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="dist/handsontable.full.css">
</head>
<body>
<div id="hot"></div>
<br />
<input id="try" type="button" value="Try" />
</body>
<script>
$(function() {
var objectData = [
{id: 1, name: 'Ted Right', address: ''},
{id: 2, name: 'Frank Honest', address: ''}];
$('#hot').handsontable({
data: objectData,
colHeaders: true,
minSpareRows: 1
});
var hot = $("#hot").handsontable('getInstance');
$("#try").click(function(){
$.getJSON("actions2.php", function(result){
console.log (objectData);
console.log (JSON.parse(result));
hot.render();
});
});
});
</script>
</html>
PHP的也很基本的
<?php
$result=array(
array("id" => 5, "name" => "Bill Gates", "address"=>"zzz"),
array("id" => 6, "name" => "Steve Jobs", "address"=>"xxx")
);
echo json_encode(json_encode($result));
?>
當我點擊「試用」按鈕,在目標數據很好更新,但並不是不顧hot.render表()指令。
有關我在做什麼錯的任何想法?
Rgds