简体   繁体   English

如何从其他Jsp调用方法/函数以将其包含在另一个Jsp的jstree中

[英]How can I call a method/function from other jsp to include in jstree in another jsp

I'm still new with jsTree , JavaScript and jQuery functions. 我对jsTreeJavaScriptjQuery函数还是很陌生 My problem is that I need to refresh the header so when I click certain nodes in jstree the header will be refreshed. 我的问题是我需要刷新标题,因此当我单击jstree中的某些节点时,标题将被刷新。

The jstree is located in applet.jsp and the function for refreshing the header is located in header.jsp. jstree位于applet.jsp中,而刷新标头的功能位于header.jsp中。

How can I call the refresh method for refreshing inside jstree? 如何在jstree中调用refresh方法进行刷新?

This is my jstree in applet.jsp: 这是我在applet.jsp中的jstree:

 var selected_folder = "folder_${user.defaultFolder}";
    $(document).ready(function() {
        jQuery("#folder_tree").jstree({
            "xml_data" : {
                 "ajax" : {
                     "url" : "<%=request.getContextPath()%>" + "/ListFolder.action" 
                 },
                "xsl" : "nest"
            },
            "ui" : {
                "initially_select" : [ "#folder_${user.defaultFolder}" ]
            },
            "types" : {
                "types" : {
                    "leaf" : {
                        "icon" : {
                            "image" : "<%=request.getContextPath()%>/images/icons/leaf.jpg" 
                        }
                    },
                    "share" : {
                        "icon" : {
                            "image" : "<%=request.getContextPath()%>/images/icons/share.jpg" 
                        }
                    }
                }
            },
            "themes" : {
                "theme" : "msam"
            },
            "plugins" : [ "themes", "xml_data", "ui", "types" ]
        });

        jQuery("#folder_tree").bind('loaded.jstree', function() {
            jQuery("#folder_tree").jstree('open_all');
          });

        jQuery("#folder_tree").bind("select_node.jstree", function(e, data) {
            var haveContent = data.rslt.obj.attr("haveContent");
            if (haveContent === 'false') {
                return;
            }
            var id = data.rslt.obj.attr("id"); 
            id = id.substring("folder_".length);
            parent.content.location.href = "<%=request.getContextPath()%>"
                                                        + "/home/Folder.action?folderID="
                                                    + id;
                                            //alert(data.inst.get_text(data.rslt.obj)); // NODE TEXT


            $.ajax({
                        url : "<%=request.getContextPath()%>" + "/WebContent/home/header.jsp",
                        data :{folderId,id},
                        cache:false,
                        success : function(data){
                        setupTree(data); //put your logic to set tree inside a method called setupTree or whatever you want to call it.
       }
 });
        });

        jQuery("#folder_tree").bind("refresh.jstree", function (event, data) {
            jQuery("#folder_tree").jstree("select_node", selected_folder);
        });


        });

            var tree_select_node = function(id) {
                selected_folder = "#folder_" + id;
                jQuery("#folder_tree").jstree("deselect_all");
                jQuery("#folder_tree").jstree("refresh");
            }

And this is the method/function for refreshing the header in header.jsp: 这是刷新header.jsp中的标头的方法/函数:

function selectHeaderLink(selectedLinkID) {
            var linkIDArray = new Array('homeLink', 'newFolderLink', 'settingsLink', 'reportsLink');
            resetHeaderLinks(linkIDArray, 'tab_link');
            if(linkIDArray.length > 0) {
                for(var i=0;i<linkIDArray.length;i++) {
                    if(linkIDArray[i] == selectedLinkID) {                  
                        var myLink = document.getElementById(linkIDArray[i]);
                        var row = myLink.parentNode;
                        row.style.height = "28";    
                        row.style.backgroundImage = 'url(../images/bg-topmenu.jpg)' ;                               
                        myLink.style.color = "white";
                        break;
                    } //--end: if-for-if
                } //--end: for-if
            } //--end: if
        }

        function windowOnload(){            
            selectHeaderLink('homeLink');


}

I already tried using an ajax request but I'm still confused where to put this ajax request. 我已经尝试过使用ajax请求,但是我仍然对将这个ajax请求放在哪里感到困惑。

Sorry for my bad English. 对不起,我的英语不好。 I hope someone will help me with this problem. 我希望有人能帮助我解决这个问题。

i already find the answer 我已经找到答案了

jQuery("#folder_tree").bind("select_node.jstree", function(e, data) {
            var haveContent = data.rslt.obj.attr("haveContent");
            if (haveContent === 'false') {
                return;
            }

selectHeaderLink('homeLink'); selectHeaderLink('homeLink');

            var id = data.rslt.obj.attr("id"); 
            id = id.substring("folder_".length);
            parent.content.location.href = "<%=request.getContextPath()%>"
                                                        + "/home/Folder.action?folderID="
                                                    + id;
                                            //alert(data.inst.get_text(data.rslt.obj)); // NODE TEXT

}); });

i just put the function into the jquery n then remove the function to centralize js file..and its work.. 我只是将函数放入jquery n中,然后删除该函数以集中化js文件..及其工作..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM