moluxiaoy 2016-06-29 03:54 采纳率: 0%
浏览 2720

jsTree ajax应该怎么写

$(function() {

$("#mechanismtree").jstree(

{

"json_data" : {

"ajax" : {

"url" :${pageContext.request.contextPath }+"/manage/mechanism/selsetMechanismtree", ///${pageContext.request.contextPath }/manage/user/mechanism_manage.jsp

                    "data" : function(n) {                              //http://localhost:8080/trainexam/manage/mechanism/selsetMechanismtree
                                // the result is fed to the AJAX request `data` option  
                                return {  
                                    "operation" : "get_children",  
                                    "id" : n.attr ? n.attr(  
                                        "id")  
                                        .replace(  
                                        "node_",  
                                        "")  
                                        : 1  
                                };  
                            }  
                        }  
                    },  

            "plugins" : [  
                        "themes",  
                        "json_data",  

                        "ui",  
                        "crrm",  
                        "contextmenu",  
                        "checkbox",
                        "search" ],  

                })  

        .bind("loaded.jstree",  
                function(event, data) {  
                })  

        .bind(  
                "select_node.jstree",  
                function(event, data) {  
                    if (data.rslt.obj  
                            .attr("id") != undefined) {  
                    }  
                })  
        .bind(  
                "remove.jstree",  
                function(e, data) {  
                    data.rslt.obj.each(function() {  
                            $.ajax({  
                                    async : false,  
                                    type : 'POST',  
                                    url : "http://localhost:8080/MemberManager/CreateNodeForDepartment",  
                                    data : {  
                                        "operation" : "remove_node",  
                                        "id" : this.id.replace("node_", "")  
                                    },  
                                    success : function(r) {  
                                        if (!r.status) {  
                                            data.inst.refresh();  
                                        }  
                                    }  
                                });  
                        });  
                })  

        .bind(  
                "create.jstree",  
                function(e, data) {  
                    $.post(  
                        "http://localhost:8080/MemberManager/CreateNodeForDepartment",  
                        {  
                            "operation" : "create_node",  
                            "id" : data.rslt.parent  
                                .attr(  
                                "id")  
                                .replace(  
                                "node_",  
                                ""),  
                            "position" : data.rslt.position,  
                            "title" : data.rslt.name,  
                            "type" : data.rslt.obj  
                                .attr("rel")  
                        },  
                        function(r) {  
                            if (r.status) {  
                                $(data.rslt.obj).attr("id", "node_" + r.id);  
                            } else {  
                                data.inst.refresh();  
                                $.jstree.rollback(data.rlbk);  
                            }  
                        });  
                })  
        .bind(  
                "rename.jstree",  
                function(e, data) {  
                    $.post(  
                        "http://localhost:8080/MemberManager/CreateNodeForDepartment",  
                        {  
                            "operation" : "rename_node",  
                            "id" : data.rslt.obj  
                                .attr(  
                                "id")  
                                .replace(  
                                "node_",  
                                ""),  
                            "title" : data.rslt.new_name  
                        },  
                        function(r) {  
                            if (!r.status) {  
                                data.inst.refresh();  
                                $.jstree.rollback(data.rlbk);  

                            }  
                        });  
                })  
                // 1) the loaded event fires as soon as data is parsed and inserted  

                // 2) but if you are using the cookie plugin or the core `initially_open` option:  
        .one("reopen.jstree",  
                function(event, data) {  
                })  
                // 3) but if you are using the cookie plugin or the UI `initially_select` option:  
        .one("reselect.jstree",  
                function(event, data) {  
                });  
        });  

这是我写的代码 我有如下两个问题需要各位大神帮忙解决啊,我是新手查了很多资料 也没有弄明白
1.jsTree的初始化数据为什么如图1这样写 ajax的代码怎么会写成 json格式?这样怎么会向后台发送数据呢?ajax不是应该是如下的写法么?

function mechanismSearch(no) {
        searchOpts.no = no;
        //alert("hhhhh");
        $.ajax({
                    url : ctx+"/manage/mechanism/selsetMechanism",
                    type : "POST",
                    data : searchOpts,
                    dataType : "json",
                    success : function(result) {
                    。。。。。。。。。。。。。。。。。。。。。。。。。。
                    }
                    ![图片说明](https://img-ask.csdn.net/upload/201606/29/1467172189_64847.png)ajax这里是json格式 我有点没搞懂?
                    2.像这样ajax代码写成json格式 那么我写请求路径的时候项目的路径怎么写?请看下面的代码 以前写路径都是这么写的。
                <c:set var="ctx" value="${pageContext.request.contextPath}" />


                $.ajax({
                    url : ctx+"/manage/mechanism/selsetMechanism",
                    type : "POST",
                    data : searchOpts,
                    dataType : "json",
                    success : function(result) {......
                    ......}


                    请各位大神们详细给我说说吧!困扰我好久了,谢谢各位!
  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2016-06-29 05:57
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮