| Issue 249: | jQuery 1.7 cannot read property 'data' | |
| 3 people starred this issue and may be notified of changes. | Back to list |
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
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
I (hopefully) fixed this with issue 247 , can you confirm?
Status:
Duplicate
Mergedinto: 247
Nov 15, 2011
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
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
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;
}
|
Does var node = $.ui.dynatree.getNode(el); ... work?Labels: Milestone-Release1.2.1