【发布时间】:2017-09-03 19:13:51
【问题描述】:
我正在尝试在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));
?>
当我点击“Try”按钮时,objectData 更新得很好,但尽管有 hot.render() 指令,表格却没有更新。
知道我做错了什么吗?
Rgds
【问题讨论】:
标签: php handsontable