My favorites | Sign in
Project Home Downloads
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 249: jQuery 1.7 cannot read property 'data'
3 people starred this issue and may be notified of changes. Back to list
Status:  Duplicate
Merged:  issue 247
Owner:  ----
Closed:  Nov 2011


 
Reported by mrdu...@gmail.com, Nov 15, 2011
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.
Nov 15, 2011
Project Member #1 moo...@wwwendt.de
Does 
    var node = $.ui.dynatree.getNode(el);
    ...
work?
Status: Waiting
Labels: Milestone-Release1.2.1
Nov 15, 2011
#2 mrdu...@gmail.com
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.
Nov 15, 2011
Project Member #3 moo...@wwwendt.de
I (hopefully) fixed this with  issue 247 , can you confirm?
Status: Duplicate
Mergedinto: 247
Nov 15, 2011
#4 mrdu...@gmail.com
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);
Dec 21, 2011
#5 mang...@zapsiteexpress.com
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;
Dec 27, 2011
Project Member #6 moo...@wwwendt.de
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;
}


Powered by Google Project Hosting