留言板
Treeview expand event
Hi,
I'm not able to set a function on the expand event (I'm using Alloy 2.0.0). It seems that I can just listen to a 'lastSelectedChange' event attached to the TreeView object.
Here's the example: http://jsfiddle.net/masieroi/3vHRk/
Any idea?
I'm not able to set a function on the expand event (I'm using Alloy 2.0.0). It seems that I can just listen to a 'lastSelectedChange' event attached to the TreeView object.
Here's the example: http://jsfiddle.net/masieroi/3vHRk/
Any idea?
I'm not able to catch the 'expand' event when I expand a node.
Here's the code:
Here's the code:
YUI().ready('aui-tree-view','io-xdr','aui-button','node', function(Y) {
var defCallback = function(event){
console.log(event.type, event);
}
var treeRootNode = new Y.TreeNode( {
cache :false,
label :'Root',
id :'root',
expanded :false,
draggable :false
});
var treeView = new Y.TreeView(
{
boundingBox: '#tree-wrapper',
children: [treeRootNode],
on : {
expand: defCallback
}
}
).render();
var node = new Y.TreeNode(
{ id: 'child',
label: 'Child',
children: [],
type: 'node',
leaf: false
}
);
var extraNode = new Y.TreeNode(
{ id: 'extraChild',
label: 'extraChild',
children: [],
leaf: true
}
);
var ROOT = treeView.getNodeById('root');
ROOT.appendChild(node);
var CHILD = treeView.getNodeById('child');
console.log(CHILD);
CHILD.appendChild(extraNode);
});
Maíra Araujo's comment in AUI-1115 (linked by Nadiya) explains how to do this. You need to listen for the expandedChange event of all the nodes ('*:expandedChange') instead of the general expanded or lastSelectedChange events. Here's a runnable example based on Ivano's JSFiddle. The expandedChange event occurs when the node is collapsed and expanded so if you want to ensure that your callback code is not executed when the node is being collapsed, you will need to do something like this:
var expandedCallback = function(event) {
var expanded = event.newVal;
if (expanded) {
/* ... your code here ... */
}
}
Side note: after making this change, I needed to change Ivano's method for logging the element's id since the expandedChange event has a different payload than the other events (event.details[0].newVal.get('id') changed to event.details[0].currentTarget.get('id')).
- Kyle
var expandedCallback = function(event) {
var expanded = event.newVal;
if (expanded) {
/* ... your code here ... */
}
}
Side note: after making this change, I needed to change Ivano's method for logging the element's id since the expandedChange event has a different payload than the other events (event.details[0].newVal.get('id') changed to event.details[0].currentTarget.get('id')).
- Kyle