简体   繁体   English

Angular 2拖放列表项

[英]Angular 2 Drag and Drop List Items

Unfortunately, I don't have the code in hand and it's more of a curious question. 不幸的是,我手头没有代码,这更是一个奇怪的问题。 Also, I don't have any experience with Angular 1 but have studied Angular 2 a bit. 另外,我对Angular 1没有任何经验,但是对Angular 2有所研究。 Is there a way for a Component to NOT render in certain conditions? 有没有一种方法可以使Component在某些情况下不呈现?

For example, say there's single vertical column that display's music song and the user can drag/drop into specific order. 例如,假设有一个垂直栏显示音乐歌曲,并且用户可以将其拖放到特定顺序。 I can do the drag-drag but I don't want Angular 2 to rerender the entire list using *ngFor because HTML is already in the correct state. 我可以进行拖动,但是我不希望Angular 2使用* ngFor重新渲染整个列表,因为HTML已经处于正确的状态。 At the same time, say 同时说

private musicItem[] : MusicItem; 私人musicItem []:MusicItem;

needs to be in sync for the order change. 需要同步以更改订单。 Any feedback would be appreciated! 对于任何反馈,我们都表示感谢! Perhaps, I'm doing this all wrong and I was thinking of using either jquery/GSAP to do drag/drop. 也许,我做错了所有事情,并且我在考虑使用jquery / GSAP进行拖放。

Don't know if you solved your problem, but I believe the easiest way is to drop an element after dragging and reorder elements in the array musicItem[] (for example, in the drop event handler if you are using ng2-dragula) and then let Angular2 rerender the list. 不知道您是否解决了问题,但我认为最简单的方法是在拖动并重新排列数组musicItem []中的元素(例如,如果使用ng2-dragula,则在drop事件处理程序中)后删除元素并删除元素然后让Angular2重新呈现列表。 At least this solution works for me. 至少此解决方案对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM