当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to get the parent folder id by the file id?

问题描述:

We are using jstree for representing the folder and file structure in our web application. When I move a file from one folder to another folder using drag and drop plugin of jstree, we need to know the folder from which it was moved.

How can we do this?

Below is my code.

<ul>

<li id="phtml_0" rel="root" class="open">

<a href="#"><ins>&nbsp;</ins></a>

<ul>

<li id="phtml_1" rel="folder"> <a><ins>&nbsp;</ins>Folder 1</a></li>

<li id="phtml_2" rel="folder"> <a><ins>&nbsp;</ins>Folder 2</a>

<ul>

<li id="phtml_11" rel="file"><a href="#"><ins>&nbsp;</ins>File 1</a></li>

<li id="phtml_22" rel="file"><a href="#"><ins>&nbsp;</ins>File 2</a></li>

</ul>

</li>

<li id="phtml_3" rel="folder"> <a><ins>&nbsp;</ins>Folder 3</a></li>

</ul>

In above case I have three folders i.e. Folder 1, Folder 2 and Folder 3.

Folder 2 has two files i.e. File 1 and File 2.

When File 1 is moved from Folder 2 to Folder 3, I need a way to find out that it was moved from Folder 2.

Basically I will need the id's of the li element of the containing folder, e.g. for File 2 (when it is moved from Folder 2), I will need the value phtml_2. (2 is the id of the Folder)

Please help.

网友答案:

This worked for me draggedObject.parent().parent().attr('id');

分享给朋友:
您可能感兴趣的文章:
随机阅读: