GithubHelp home page GithubHelp logo

Comments (6)

mbraak avatar mbraak commented on May 19, 2024

Version 0.11 of jqTree has the tree.init event. This event is fired when the tree data is loaded. It is not documented yet.

JqTree does not support mouse-over, but you can write it yourself like this:

$tree.on('hover', '.title', function(e) {
  var $li = $(e.target).closest('li');
  var node = $li.data('node');
  console.log(node);
});

I'm not sure if I want to add the getParents function to jqTree because I don't know how many people will use it. You could however implement it in your own code, like this:

var node = $tree.tree('getNodeByName', 'Hadrosaurids');
var parents = [];
var parent = node.parent;
while (parent) {
  parents.push(parent);
  parent = parent.parent;
}

It should indeed be possible to display an empty folder. More people have mentioned this, and I'm still thinking about the best api for this. Perhaps an empty children property is a good option.

from jqtree.

SirCumz avatar SirCumz commented on May 19, 2024

maybe typeof() is also good.

i downloaded the latest version 0.11 and the tree.init event works :)

but when i try to get the selected node it returns null!

but i can see that a node (by cookie or savestate ) has been selected on startup, but when i try to get the selected node on the tree.init event it returns null.

here is the code:

$tree.bind(
'tree.init',
function(e)
{
var node = $tree.tree('getSelectedNode');
alert(node)
}
);

For my application to work i realy need to get the selected node on tree.init, so i can fill my second tree with the associated files. any ideas?

from jqtree.

mbraak avatar mbraak commented on May 19, 2024

Strange. I tried it with example2 (http://mbraak.github.com/jqTree/examples/example2.html) with the following code:

$tree = $('#tree1');
$tree.tree({
  selectable: true,
  saveState: true
});

$tree.bind('tree.init', function() {
  var node = $tree.tree('getSelectedNode');
  console.log(node);
});

A small detail: for saveState to work, nodes must have an id property. Example:

{
  label: 'Sauropodomorphs',
  id: 16
}

from jqtree.

SirCumz avatar SirCumz commented on May 19, 2024

well i use ID's and labels.

this is my tree config:

{
     data: data,

     autoOpen: 0,

      dragAndDrop: false,

      selectable: true,

      saveState: true
}

But on the tree.init event only null returns.

Like i said "i use ID's for nodes"

I looked at example2 but the log is empty. i use google chrome maybe thats the issue?

** EDIT **

IE also returns null. just checked it.

from jqtree.

mbraak avatar mbraak commented on May 19, 2024

I'm afraid you found an error in jqTree. If you call getSelectedNode in the tree.init event it returns null.

However, you can call getSelectedNode after initializing the tree:

$tree.tree({
  data: data,
  selectable: true,
  saveState: true
});

var node = $tree.tree('getSelectedNode');
console.log(node);

from jqtree.

SirCumz avatar SirCumz commented on May 19, 2024

Yes that works!

but i found also a workaround for the tree.init event

  $tree.bind(
      'tree.init',
      function(e) 
      {
        var $li = $tree.find('li.selected');
        var node = $li.data('node');
        alert(node.name)
      }
  ); 

from jqtree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.