Angular.js: Is it possible to re-render ng-repeats based on existing scope data?

邮差的信 提交于 2019-11-30 14:38:54

问题


I have a bunch of connected ul lists in my view which are using a jQuery UI: Sortable directive to facilitate drag and drop and reordering of the list items.

Changes I make via jQuery UI's drag and drop I apply to the $scope using the $apply function, this part works…

The issue I am running into now however is that on drop into some of these lists I provide a custom form that the user needs to fill out.

The user has the option to:

  1. fill out the form and continue which then does the $apply call to persists the data into the $scope
  2. click a cancel button which instead of calling the $apply to store info, should revert the last drag/drop interaction effectively 're-rendering' all my lists to reflect the data that is still in the $scope at this stage (since the latest drag had not had any effect on it yet).

The effect of this "cancel" button is effectively reverting everything to the point before the user picked up the list item and dragged it into another list.

How can I force a 'refresh' or 're-render' of my ng-repeats so that they visually refresh and show the current $scope data again?


回答1:


When the user starts filling out the form, I would set

$scope.oldData = angular.copy($scope.data);

Then let the user edit $scope.data using the form as he likes.

Then if the user presses cancel, just set $scope.data = $scope.oldData.



来源:https://stackoverflow.com/questions/12595656/angular-js-is-it-possible-to-re-render-ng-repeats-based-on-existing-scope-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!