Forums de discussion

How to get the selected treeview nodes' labels and ids?

Kurt Xu, modifié il y a 10 années.

How to get the selected treeview nodes' labels and ids?

Junior Member Publications: 57 Date d'inscription: 02/02/13 Publications récentes
<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.liferay.portal.service.OrganizationLocalServiceUtil" %>
<%@page import="com.liferay.portal.model.Organization" %>
<%@ page import="com.test.SearchableTreeNode" %>
<%@ page import="com.test.OrgTree" %>
<%@ include file="init.jsp" %>
<%!
    public String printSubOrg(Organization org) throws SystemException {
        StringBuffer sb = new StringBuffer("\n");
        for (Organization organization : org.getSuborganizations()) {
            sb.append("\t\t" + organization.getName() + "\n");
        }

        return sb.toString();
    }

%>

<%
    //    List<organization> orgs = OrganizationLocalServiceUtil.getOrganizations(company.getCompanyId(), 39401);
    List<organization> orgs = OrganizationLocalServiceUtil.getOrganizations(0, 1000);
    OrgTree orgTree=new OrgTree();

    System.out.println(orgTree.makeTreeJS("myTreeView"));

%&gt;

there are &lt;%=orgs.size() %&gt;  orginaztions found

<div id="myTreeView"></div>
<div id="myTreeView2"></div>
<div id="myTreeView3"></div>

<div id="overlay-blue"></div>

<aui:button type="button" id="get" value="Get Selected" />


<script type="text/javascript" charset="utf-8">

    AUI().use(
            'aui-tree-view',
            function (Y) {
              var orgTree=  new Y.TreeViewDD(
                        {
                            boundingBox: '#myTreeView',
                            children: [
                                        {
                                            children:[
                                                {label: 'PSI', leaf: true, type: 'task'},
                                                {
                                                    children:[
                                                        {label: 'Marketing', leaf: true, type: 'task'},
                                                        {label: 'Buying', leaf: true, type: 'task'}
                                                    ],
                                                    expanded:true,
                                                    label:'GO',
                                                    type:'task'

                                                }
                                            ],
                                            expanded:true,
                                            label:'Haier',
                                            type:'task'
                                        }
                            ]
                        }
                ).render();

                Y.on('click',function(event){
                    orgTree.eachChildren(function(node){
                        alert(node.label)
                    },function(){})
                },'#get')
            }
    );


</script>

</organization></organization>


I tried code above, but labels can't be got, saying 'undefined' for every alerting. Why?
thanks.
thumbnail
Byran Zaugg, modifié il y a 10 années.

RE: How to get the selected treeview nodes' labels and ids?

Expert Publications: 252 Date d'inscription: 06/04/12 Publications récentes
Kurt,

You'll need to use:
node.get('label')

as label is an attribute and not a property of Tree Node
See: http://alloyui.com/versions/1.7.x/api/classes/TreeNode.html
Kurt Xu, modifié il y a 10 années.

RE: How to get the selected treeview nodes' labels and ids?

Junior Member Publications: 57 Date d'inscription: 02/02/13 Publications récentes
Byran Zaugg:
Kurt,

You'll need to use:
node.get('label')

as label is an attribute and not a property of Tree Node
See: http://alloyui.com/versions/1.7.x/api/classes/TreeNode.html



Yes, you are right, and get('id') returns the id of the node. thanks ,buddy