【问题标题】:Get Parent's Parent Id in jqxtree drag in dragEnd Event在dragEnd事件中拖动jqxtree中获取Parent的Parent Id
【发布时间】:2014-01-04 10:30:47
【问题描述】:

我正在使用 JQXTree,一个示例 Html 代码

<div id='treeA' style='float: left; margin-left: 0px;'>
<ul>
    <li id='home' item-selected='true'>Server</li>
        <li item-expanded='true'>Incoming Data
            <ul>
            <li>FTP Adapter</li>
            <li item-expanded='true'>RDBMS
            <ul>
                         <li draggable="true">ftpConnection1</li>
                         <li id='ftpConnection2'>ftpConnection2</li>
            </ul>
        </li>
    <li>NoSql Adapter</li>
    <li>RSS Adapter</li>
    <li>MQTT Adapter</li>
    <li>ZMQ Adapter</li>
    </ul>
   </li>
 </ul>
</div>

$('#treeA').jqxTree({ allowDrag: true, allowDrop: true,  theme: theme});

如果我拖动 ftpConnection1 在图像中,我需要获取父 ID FTP Adapter 及其父 ID Incoming Data

我在树上使用 dragEnd 事件

$("#treeA").on('dragEnd', function (item) {  
            console.log(item);
       var droppedToolId = item.args.owner._dragItem.id;
       var parentId = item.args.owner._dragItem.parentId;
});

所以我得到了 Parent Id,我需要为我丢弃的项目获取 Parent 的 Parent Id。

有什么建议吗?

【问题讨论】:

  • var parentId 持有你父母的 id?
  • 当我尝试item.args.owner._dragItem.id 时,我只得到null for _dragItem

标签: javascript jquery drag-and-drop jqxwidgets


【解决方案1】:

我希望你没有重复的 ID 试试

$("#treeA").on('dragEnd', function (item) {  
            console.log(item);
       var droppedToolId = item.args.owner._dragItem.id;
       var parentId = item.args.owner._dragItem.parentId;
       var Pid = $('#'+parentId).parent().attr('id');//get parent
       alert(Pid);
});

【讨论】:

    【解决方案2】:

    试试这个代码 sn-p:

    $('#treeA').jqxTree({ allowDrag: true, allowDrop: true, height: '300px', width: '220px', 
                    dragEnd: function (item, dropItem, args, dropPosition, tree) {
                        if (item.level != dropItem.level && item.parentId != dropItem.parentId)
                            return false;
                    }   
                    oldParentId = item.parentId;
                    newParentId = dropItem.parentId;          
            });
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      相关资源
      最近更新 更多