jsTree ajax 怎么初始化数据的

moluxiaoy 2016-06-29 11:17:22
我现在需要写一个jsTree树 于是通过找资料写了如下代码:
$(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我想问问ajax怎么会写成json的格式?一般写ajax不是都类似于下面的写法么?
$.ajax({
url :${pageContext.request.contextPath }+"/manage/mechanism/selsetMechanism",
type : "POST",
data : searchOpts,
dataType : "json",
success : function(result) {
.................................................................}

....
如果写成json它是怎么向后台发的数据啊??
2.第二个问题是ajax在这里路径应该怎么写啊?就是怎么获得项目的路径?如图二,会报错啊!




...全文
258 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 2 楼 moluxiaoy 的回复:
谢谢哈 我想问一下 那代码里面写的json_data里面的ajax怎么去后台访问数据的?也就是ajax写的是json的格式啊不是js代码
用的还是jquery的ajax。都说了那个是jstree需要的配置,不是jquery的,jstree的代码会自动提取配置来调用jquery.ajax获取数据
moluxiaoy 2016-06-29
  • 打赏
  • 举报
回复
谢谢哈 我想问一下 那代码里面写的json_data里面的ajax怎么去后台访问数据的?也就是ajax写的是json的格式啊不是js代码
  • 打赏
  • 举报
回复
1,你得看人家的api怎么用,不是你想怎么搞就怎么搞的,你贴的那个是jquery.ajax的api需要的配置,别人代码里面自动会调用传入的配置进行相关处理 2,第一张截图你ctx变量定义没有 第二张${page...}放入'/imanage/...里面,就是 "url":"${page...}/imanage/..." 放外面会导致服务器端编译后生成的js代码出问题

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧