iterate throught children nodes

42 views
Skip to first unread message

Viktor Dušenka

unread,
Mar 18, 2014, 6:01:20 PM3/18/14
to enf...@googlegroups.com
Hello

can somebody help me how to iterate throught nodelist ?
i have:

(ef/at ".tabs" #(for [node (.-childNodes (.-currentTarget %))]
                   (js/alert (.-nodeValue node)))))

only to get some info about node, but it fails with TypeError: p1__4149_SHARP_.currentTarget is undefine, why ?

html is:
<div class="tabs">
<div class="tab" id="user1">
                <span class="tab-name">user 1
                    <span class="exit-btn">x</span>
                </span>               
            </div>
</div>

xavi

unread,
Mar 18, 2014, 6:46:38 PM3/18/14
to enf...@googlegroups.com
currentTarget is a property of a event, isn't it?

...but Enfocus' `at` form calls the "transformation" (your anonymous function) with each node matched by the selector (".tabs"). So, in your anonymous function, % is a node, not an event.

Hope that helps,
Xavi

Viktor Dušenka

unread,
Mar 18, 2014, 7:24:22 PM3/18/14
to enf...@googlegroups.com


Dne úterý, 18. března 2014 23:01:20 UTC+1 Viktor Dušenka napsal(a):
Thanks xavi,

i didn't realize it, my purpose is to append new <div  class="tab"> with id="username" only if there isnt already, i still finding solution ... but unsuccessfully /

xavi

unread,
Mar 18, 2014, 7:52:24 PM3/18/14
to enf...@googlegroups.com
It can probably be done, but I can't think of a solution off the top of my head.

However, it seems that you're using the DOM to store model data (your list of users). It will probably be simpler if you keep that list on a ClojureScript atom for example. Then you would check if a user is in that list, and if not, you could just add it with something like (not tested)...

(ef/at ".tabs" (ef/append (ef/html [:div.tab {:id "username"}])))

Cheers,
Xavi

Viktor Dušenka

unread,
Mar 18, 2014, 7:57:52 PM3/18/14
to enf...@googlegroups.com

Yes i already do it this way, but problem is, not to have multiple tabs with same user, so first i want to check if tab with this username exist if not append else focus


Dne středa, 19. března 2014 0:52:24 UTC+1 xavi napsal(a):

xavi

unread,
Mar 18, 2014, 7:58:17 PM3/18/14
to enf...@googlegroups.com

On Wednesday, March 19, 2014 12:52:24 AM UTC+1, xavi wrote:
It can probably be done, but I can't think of a solution off the top of my head.

However, it seems that you're using the DOM to store model data (your list of users). It will probably be simpler if you keep that list on a ClojureScript atom for example. Then you would check if a user is in that list, and if not, you could just add it with something like (not tested)...

(ef/at ".tabs" (ef/append (ef/html [:div.tab {:id "username"}])))

I meant that, if not, you could just add it to both, your model data (ie the atom) and the DOM. The latter addition using that code.

Xavi 
 

ckirkendall

unread,
Mar 18, 2014, 8:05:35 PM3/18/14
to enf...@googlegroups.com
I am with Xavi on this one it is probably better to keep the tab state separate from the dom and then render the dom based on the tab state.  This is key concept to the idea of transforms where we combine dynamic state with a dom to produce an new dom.   That being said you can certainly do it the other way.

(let [user (ef/from "div.tab[id='user1']" (get-attr :id))]
    (when-not user (ef/at ".tabs"  (append ...))))
   

CK

Viktor Dušenka

unread,
Mar 18, 2014, 8:18:45 PM3/18/14
to enf...@googlegroups.com
woow it's nice solution, i already got all tab ids, but this is really nice,
i didn't realize that solution, big thanks to you both :) and also for quick replys :)

Dne středa, 19. března 2014 1:05:35 UTC+1 ckirkendall napsal(a):
Reply all
Reply to author
Forward
0 new messages