angularjs – 在回调事件中触发摘要循环
发布时间:2020-12-17 17:00:46 所属栏目:安全 来源:网络整理
导读:我想创建一个相应的textarea以及handstontable,这样修改表对文本有影响,反之亦然.这是一个 JSBin. !DOCTYPE htmlhtmlhead script src="https://handsontable.github.io/ngHandsontable/node_modules/angular/angular.js"/script script src="https://docs.ha
我想创建一个相应的textarea以及handstontable,这样修改表对文本有影响,反之亦然.这是一个
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:无法将属性’forceFullRender’设置为null: 在其他回调中使用$scope.$digest()(即onAfterCreateCol,onAfterRemoveRow和onAfterRemoveCol)将引发相同的错误.如果我们不能在这些回调事件中很好地触发摘要周期,我认为这是一个严重的问题.有谁知道如何解决这个问题或有任何解决方法? 解决方法
$timeout是目前某些旧版本角度的变通方法,您可以使用$applyAsync创建替换$timeout作为变通方法,并适用于您将收到错误的情况$digest已在进行中
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |