码迷,mamicode.com
首页 > 其他好文 > 详细

easyui中combotree循环获取父节点至根节点并输出路径

时间:2015-01-28 17:52:52      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:easyui   combotree   获取   父节点   路径   

前台页面:

<pre name="code" class="html"><td style="height: 35px" colspan="7">
      <input id="fm_AEType" class="easyui-combotree" style="width: 240px" />
      <label id="fm_AETypePath" />
</td></pre>

JavaScript页面(包括数据初始化):

initAEType: function () {
    $.ajax({
        url: AEActionUrl + '?action=listaetype&ParentType=',
        dataType: 'json',
        success: function (jsonstr) {
            $('#fm_AEType').combotree({
                data: jsonstr,
                editable: false,
                //lines: true,
                valueField: 'AE_TYPE_ID',
                textField: 'AE_TYPE_NAME',
                onLoadSuccess: function () {
                    $('#fm_AEType').combotree('tree').tree("collapseAll");
                },
                onSelect: function (item) {
                    var parent = item;
                    var tree = $('#fm_AEType').combotree('tree');
                    var path = new Array();
                    do {
                        path.unshift(parent.text);
                        var parent = tree.tree('getParent', parent.target);
                    } while (parent);
                    var pathStr = '';
                    for (var i = 0; i < path.length; i++) {
                        pathStr += path[i];
                        if (i < path.length - 1) {
                            pathStr += ' - ';
                        }
                    }
                    $('#fm_AETypePath').text(pathStr);
                }
            });
        }
    });
}

如上,关键代码在onSelect事件中。


easyui中combotree循环获取父节点至根节点并输出路径

标签:easyui   combotree   获取   父节点   路径   

原文地址:http://blog.csdn.net/jumtre/article/details/43233685

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!