0

方法insertBefore是如何工作的?

asked 2012-09-17 10:55:41 +0800

cbyyni gravatar image cbyyni
23 1

HI, all:

我需要一个拖放效果在我的项目中。 我参考了ZK官网的demo- http://www.zkoss.org/zkdemo/effects/drag_n_drop
我大概明白其中的工作原理。容器(demo中的listbox)的onDrop事件被触发时,它添加dragged作为自己的child,这个
好理解,那么,在listitem的onDrop事件发生时,调用的insertBefore是什么意思?移动源的item是怎么消失的?谁调用
了remove的方法?

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2012-09-17 18:34:36 +0800

jj gravatar image jj
638 3

Here is the code in the demo:

 void move(Component dragged) {
            if (self instanceof Listitem) {
                self.parent.insertBefore(dragged, self);
            } else {
                self.appendChild(dragged);
            }
        }

self.parent. insertBefore(dragged, self) means inserting the "dragged" before "self" as a child of ("self.parent")

Once you move the item to be a child of another component, it is automatically detached from its original parent

link publish delete flag offensive edit

answered 2012-09-18 01:37:34 +0800

cbyyni gravatar image cbyyni
23 1

hi,jj

Thanks a lot for your help


Best regards
jennings

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-09-17 10:55:41 +0800

Seen: 79 times

Last updated: Sep 18 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More