angular.js - angular 做拖拽交互的时候到底是用js改变dom好,还是只改变数据好?
ringa_lee
ringa_lee 2017-05-15 17:06:50
0
2
694

网上搜索推荐不要改变dom,但是只改变数据会导致重新渲染,原本打开的下拉项就会被关闭。交互效果不好。但是用js改变dom,数据又会变得很难处理

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