留言板

Treeview expand event

Ivano Masiero,修改在10 年前。

Treeview expand event

New Member 帖子: 15 加入日期: 10-7-7 最近的帖子
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?
Ivano Masiero,修改在10 年前。

RE: Treeview expand event

New Member 帖子: 15 加入日期: 10-7-7 最近的帖子
I'm not able to catch the 'expand' event when I expand a node.
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);

        });
Nadiya Sadath,修改在7 年前。

RE: Treeview expand event

New Member 发布: 1 加入日期: 15-10-8 最近的帖子
thumbnail
Kyle Joseph Stiemann,修改在7 年前。

RE: Treeview expand event

Liferay Master 帖子: 760 加入日期: 13-1-14 最近的帖子
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