angular.js - When doing drag-and-drop interaction in angular, is it better to use js to change the dom, or only change the data?
ringa_lee
ringa_lee 2017-05-15 17:06:50
0
2
718

Online searches recommend not to change the DOM, but changing only the data will cause re-rendering, and the originally opened drop-down items will be closed. The interaction effect is not good. But if you use js to change the dom, the data will become difficult to process

ringa_lee
ringa_lee

ringa_lee

reply all(2)
小葫芦

Angular tries to avoid DOM operations. Functions such as drag and drop can modify data and apply it to elements through ng-style. A better solution would be to implement it by defining instructions

小葫芦

My suggestion is: If it is a large-scale interactive operation, such as dragging a tree structure with thousands of children, then it is best for you to save a temporary data and then update the DOM at once. If you rely on Angular's data binding, the browser will probably hang.
If you have just dozens or hundreds, you can directly use the ng-xx directive to implement interactive logic using data.

PS: When Angular does data synchronization, a watch will be generated for each place that requires data binding, so the thousands and hundreds mentioned above refer to the number of watches.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template