対応するテキストエリアをハンドスタンドと一緒に作成して、テーブルの変更がテキストに影響を与えるようにしたい。ここにはJSBinがあります。コールバックイベントのダイジェストサイクルをトリガーする
<!DOCTYPE html>
<html>
<head>
<script src="https://handsontable.github.io/ngHandsontable/node_modules/angular/angular.js"></script>
<script src="https://docs.handsontable.com/pro/1.8.2/bower_components/handsontable-pro/dist/handsontable.full.js"></script>
<link type="text/css" rel="stylesheet" href="https://docs.handsontable.com/pro/1.8.2/bower_components/handsontable-pro/dist/handsontable.full.min.css">
<script src="https://handsontable.github.io/ngHandsontable/dist/ngHandsontable.js"></script>
</head>
<body ng-app="app">
<div ng-controller="Ctrl">
<hot-table settings="settings" on-after-create-row="onAfterCreateRow" datarows="dataJson"></hot-table>
<br><br>
<textarea cols=40 rows=20 ng-model="dataString"></textarea>
</div>
<script>
var app = angular.module('app', ['ngHandsontable']);
app.controller('Ctrl', ['$scope', '$filter', 'hotRegisterer', function ($scope, $filter, hotRegisterer) {
$scope.dataJson = [[5, 6], [7, 8]];
$scope.onAfterCreateRow = function (index, amount) {
$scope.$digest();
};
$scope.$watch('dataJson', function (dataJson_new) {
$scope.dataString = $filter('json')(dataJson_new);
}, true);
$scope.$watch('dataString', function (dataString_new) {
try {
$scope.dataJson = JSON.parse(dataString_new);
} catch (e) {
}
}, true);
$scope.settings = {
contextMenu: true,
contextMenuCopyPaste: {
swfPath: 'zeroclipboard/dist/ZeroClipboard.swf'
}
};
}]);
</script>
</body>
</html>
しかし、私が気付いて一つのことは、行/列を削除/追加すると、(セル値がどうなるの変更に対し)dataJSON
のウォッチャを発生しません、ということです。ですから、私はonAfterCreateRow
のようなコールバックで$scope.$digest()
を使用して、行を追加する変更を反映させる必要があります。しかし、それは、Uncaught TypeError: Cannot set property 'forceFullRender' of null
を発生させます:
他のコールバックで$scope.$digest()
(すなわち、onAfterCreateCol
、onAfterRemoveRow
とonAfterRemoveCol
)を持つことは、同じエラーが発生します。これらのコールバックイベントでダイジェストサイクルをうまく起動できない場合は、深刻な問題だと思います。誰もがこれを解決する方法を知っている、または任意の回避策がありますか?
実際には、 '$ scope。$ applyAsync()'が動作します。そして、 '$ scope。$ evalAsync()'も同様です。 –