2017-02-01 10 views
4

対応するテキストエリアをハンドスタンドと一緒に作成して、テーブルの変更がテキストに影響を与えるようにしたい。ここには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を発生させます:

screen shot 2017-02-01 at 17 07 55

他のコールバックで$scope.$digest()(すなわち、onAfterCreateColonAfterRemoveRowonAfterRemoveCol)を持つことは、同じエラーが発生します。これらのコールバックイベントでダイジェストサイクルをうまく起動できない場合は、深刻な問題だと思います。誰もがこれを解決する方法を知っている、または任意の回避策がありますか?

答えて

0

$timeoutは、現在の角度の一部の古いバージョンでは回避策だったあなたはそれが動作エラー$digest already in progress

+0

実際には、 '$ scope。$ applyAsync()'が動作します。そして、 '$ scope。$ evalAsync()'も同様です。 –

0

この問題を解決する方法としては、いわゆる、$timeoutというサービスを使用する方法があります。ここをクリックしてJSBinを更新してください。また、$timeoutがどのように働くのかの説明を見ると、答えはHereです。これが役立つことを願っています。

+0

になるだろう場合の回避策と作品として$タイムアウトを置き換えるために作成された$applyAsyncを使用することができ、感謝あなたは... –

関連する問題