findFirst - TypeError

166 views
Skip to first unread message

Sergey Dashko

unread,
Oct 10, 2017, 8:53:44 PM10/10/17
to Fancytree Q&A
Hello.
I'm trying to find node by id using findFirst function like this:
$("#tree").fancytree("getRootNode").findFirst(function(node){node.key == id})
but get this error:
"jquery.fancytree-all-deps.min.js:20 Uncaught TypeError: a.toLowerCase is not a function"
What I'm doing wrong?
I can actually find needed tr using Jquery but how can I access node having that tr?

Thanks in advance,
Sergey

mar10

unread,
Oct 13, 2017, 2:29:46 AM10/13/17
to Fancytree Q&A
Could you post an jsFiddle or Plunkr that reproduces this?

Sergey Dashko

unread,
Oct 14, 2017, 3:09:37 AM10/14/17
to Fancytree Q&A
Here you are http://plnkr.co/edit/WSizav?p=preview
Test button adds new child and then use findFirst to find added child and alert it's title.
May be I'm doing something wrong. Please, help me with this.

Regards,
Sergey

mar10

unread,
Oct 14, 2017, 10:49:49 AM10/14/17
to Fancytree Q&A
The problem is here: You do
     var newNode = $("#tree").fancytree("getTree").findFirst(function(node){
          node.key == rand
        })

 but you should do
   var newNode = tree.findFirst(function(node){
         
return node.key === rand;
       
})

However you don't need this, since the add method already returns it:
    var newNode = parentNode.addChildren({title: "Child" + rand, key: rand, checkbox: true, folder: true});

 
Btw. 
- Keys should be strings (not int)
-  you should use a glyph theme when bootstrap is included. For example skin-bootsrap
- and this does not work:
    var selectedNodes = tree.getSelectedNodes()
   
if(selectedNodes === 0){

because getSelectedNodes() returns an array.
Reply all
Reply to author
Forward
0 new messages