cloning element with behavior and need to apply it..

14 views
Skip to first unread message

Rolf-nl

unread,
Jul 1, 2012, 7:10:44 AM7/1/12
to clien...@googlegroups.com
Back using Behavior/Delegator..

I'm used to inserting new elements into to the dom using delegator and then firing ammendDom (much like delegator.ajax example) so that possible behavior on those elements are applied.

But now I have an element with a "cloning" behavior declared. The dom is updated and I need to invoke/apply the behaviors for these cloned elements (from inside the original behavior causing the clone).
Because the clones (LI's in this case) are not inserted into a new target container I can not easily do api.applyFilters(target). If I run this on the parent UL-element (as if that was the target) I get unexpected results too (behaviors inside the parent are then applied in a loop).

How should this be approached? I have it working, but that's using some ugly code :)

Rolf

Aaron Newton

unread,
Jul 1, 2012, 12:14:25 PM7/1/12
to clien...@googlegroups.com
1) it shouldn't matter if you call behavior's apply on a container with elements that already have the behaviors applied, it should ignore them.

2) there's a method passed through the API argument - I think it's called applyBehaviors ? - that lets you call the behavior instance's apply method on elements you create. 

So you an either call apply on elements as you add them or on the parent element when you're done.


--
You received this message because you are subscribed to the Google Groups "Clientcide" group.
To view this discussion on the web visit https://groups.google.com/d/msg/clientside/-/zOSjBnyEJ80J.
To post to this group, send email to clien...@googlegroups.com.
To unsubscribe from this group, send email to clientside+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/clientside?hl=en.

Rolf-nl

unread,
Jul 1, 2012, 5:30:08 PM7/1/12
to clien...@googlegroups.com
What you write is what I thought and was expecting.. but I'm getting something else..
I will start to breakdown my code and isolate the problem with a demo.
To unsubscribe from this group, send email to clientside+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages