pcirella / dynatree

Automatically exported from code.google.com/p/dynatree
0 stars 0 forks source link

jQuery 1.7 cannot read property 'data' #249

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. use jquery 1.7
2. try to access dynatree node's data: node.data

What is the expected output?
- it worked with jquery 1.6.x

What do you see instead?
- JS error: Uncaught Type Error: Cannot read property 'data' of undefined

I'm using Chrome
========================

Below is HTML code that used to work: (it popups a Context menu when right 
click on a Node)

function bindTreeContextMenu() {
    // http://abeautifulsite.net/2008/09/jquery-context-menu-plugin/
    // Add context menu to all tree nodes:
    $('span.dynatree-node').destroyContextMenu().contextMenu(
        { menu : 'treeMenu' },
        function(el) {
            console.log(el);
            console.log(el.parents('[dtnode]'));
            var node = el.parents('[dtnode]').prop('dtnode');
            var nodeKey = node.data.key;

            //var nodeKey = el.parent().attr('title');
            dtree.activateKey(nodeKey);
        },

======
Error happened in "var nodeKey = node.data.key;" line...
Thanks.

Original issue reported on code.google.com by mrdu...@gmail.com on 15 Nov 2011 at 6:40

GoogleCodeExporter commented 9 years ago
Does 
    var node = $.ui.dynatree.getNode(el);
    ...
work?

Original comment by moo...@wwwendt.de on 15 Nov 2011 at 7:12

GoogleCodeExporter commented 9 years ago
console.log(el):

<span class=​"dynatree-node dynatree-expanded dynatree-has-children 
dynatree-exp-e dynatree-ico-e">​
  <span class=​"dynatree-expander">​</span>​
  <span style=​"display:​ inline-block" id=​"ic_1__100194">​</span>​
  <a href=​"#" class=​"dynatree-title">​Sample​</a>​
</span>​
]

var node = $.ui.dynatree.getNode(el);
console.log(node):
undefined

It seems not be able to get the node.

Original comment by mrdu...@gmail.com on 15 Nov 2011 at 7:27

GoogleCodeExporter commented 9 years ago
I (hopefully) fixed this with issue 247, can you confirm?

Original comment by moo...@wwwendt.de on 15 Nov 2011 at 8:34

GoogleCodeExporter commented 9 years ago
Thanks a lot, that fixed it!

var node = el.parents('[dtnode]').prop('dtnode'); doesn't work,
but this works now: (r533)
var node = $.ui.dynatree.getNode(el);

Original comment by mrdu...@gmail.com on 15 Nov 2011 at 9:41

GoogleCodeExporter commented 9 years ago
Testing with DynaTree 1.2.0 release on Windows Server 2003:
Firefox 8: getNode does not work
Chrome 16: getNode does not work
IE8: getNode works

This works in FF8, Chrome 16, and IE 8:

var $el = el.jquery === undefined ? $(el) : el;
var node;

$.each( $el.parents(), function( index, parent ) {
    node = parent.dtnode;

    if( node ) {
        return false;
    }
});

return node;

Original comment by mang...@zapsiteexpress.com on 21 Dec 2011 at 5:54

GoogleCodeExporter commented 9 years ago
The latest release uses plain JS (not jQuery).
Hope this works on all browsers:

$.ui.dynatree.getNode = function(el) {
    if(el instanceof DynaTreeNode){
        return el; // el already was a DynaTreeNode
    }
    while( el ) {
        if(el.dtnode) {
            return el.dtnode;
        }
        el = el.parentNode;
    }
    return null;
}

Original comment by moo...@wwwendt.de on 27 Dec 2011 at 8:01