如何使用jQuery或JavaScript获取treeview的每个元素的路径?

时间:2018-08-10 11:54:49

标签: javascript jquery ajax

我已经使用jquery设计了TreeView,并且它与ajax响应(动态地)绑定。

现在,我希望每个li元素的OnClick()都显示folder1 > Folder 1-1 > Folder 1-1-1之类的路径,依此类推

Tree View structure

我的DOM代码是:

function loadSubFolders(folderId) {
  $.ajax({
    dataType : "json",
    url : "loadChildFolders",
    type : 'GET',
    data : {id : folderId},
    success : function(response) {
        if (response.length != null) {
            for (i = 0; i < response.length; i++) {
                $(".treeOne").append("<li id="+response[i].folderId+" value="+response[i].folderNm+"><a>"+ response[i].folderNm
                        + "</a><ul class="+response[i].folderId+"></ul></li>");
                
                var subList = response[i].listOfFolder;
                getChildSubFolder(subList,response[i].folderId);
            }
        }
        $('#tree1').treed();
    },
    error : function(res, textStatus) {
        var msg = "Unable to load Subfolder";
        alert(msg);
    }
  });
}

function getChildSubFolder(subList, parentId) {
  if (subList.length > 0) {
    var count = subList.length;
    for (j = 0; j < count; j++) {
        var temp = j;
        if (parentId == subList[j].rootId) {
            $("." + parentId).append("<li id="+subList[j].folderId+" value="+subList[j].folderNm+"><a>"+ subList[j].folderNm
                + "</a><ul class="+subList[j].folderId+"></ul></li></ul>");
            
            var subChildList = subList[j].listOfFolder;
            if (subChildList.length > 0) {
                getChildSubFolder(subChildList,
                        subList[j].folderId);
            }
            j = temp;
        }
    }
  }
}

我该怎么办?

请帮助我!

0 个答案:

没有答案