【发布时间】:2013-04-09 07:16:28
【问题描述】:
我试图在单击父节点(类别)时获取子节点(在我的情况下为子类别)。但我可以看到在我的情况下没有发生 ajax 请求。我已经使用了这个网站上的解决方案 - (http://www.miketyka.com/2012/10/lazy-loading-with-jstree-and-ajax/)。下面是我的 jstree 代码 -
/**
* menu tree generation
*/
$("#menu_tree")
.bind("open_node.jstree", function (e, data) { // this binding will collapse all nodes whenever user expands any single node
data.rslt.obj.siblings().filter(".jstree-open").each(function () {
data.inst.close_node(this);
});
})
.jstree({
"json_data": {
"ajax": {
"url": base_url + "draw/get_child"
}
},
"types": { // this will let user to expand or collapse node by clicking on the node title
"types": {
"default": {
"select_node": function (e) {
this.toggle_node(e);
return false;
}
}
}
},
"core": {
"html_titles": true,
"load_open": true
},
"plugins": ["themes", "json_data", "html_data", "types", "ui"],
"themes": {
"theme": "apple",
"dots": true,
"icons": true
}
});
html 部分如下 -
<div class="" id="menu_tree" style="width: 500px;z-index: 1; float: right;position: relative;">
<ul class="" style="position: absolute;top: 0px;left: 0px;">
<?php
if (!empty($parent_categories)) {
foreach ($parent_categories as $parent_categories) {
?>
<li id="cat<?php echo $parent_categories->objcat_id; ?>">
<a href="#" class=""><?php echo $parent_categories->category_name; ?></a>
</li>
<?php
}
}
?>
</ul>
</div>
我想要获取的数据如下 - (我正在使用 codeigniter)
$this->load->model('object_category_model');
$result = array();
$sub_category = $this->object_category_model->get_subcategories_by_category_id($this->input->post('parent_id'));
echo json_encode($sub_category);
我只是第一次加载父节点,所有子节点都应该通过用户点击父节点来加载。
如果我使用“html_data”而不是“json_data”,则会出现请求,我可以看到加载 gif,但随后我收到此错误“Uncaught Error: NotFoundError: DOM Exception 8”,但如果我使用“json_data”则什么都没有发生,萤火虫中没有 ajax 请求。
我不明白我在做什么错...请问有什么解决办法吗?
【问题讨论】:
-
你能看到什么 int firebug?是否发送了 AJAX 请求?网络服务器是否接收到它?简化您的代码。仅使用 ajax 中的 url 开始。不确定“load_open”是做什么的。以前没用过。
-
@Radek --- 没有发送 ajax 请求,这就是问题所在,因为我什至不明白在哪里可以找到错误...
-
@Radek --- 我正在尝试通过使用 ajax 动态单击父节点名称来加载子节点。
-
简化您的代码。仅使用没有任何功能的 url 开始。然后开始添加越来越多的代码。没有“类型”,没有“成功”属性,只有普通的“url”。
-
@Radek -- 我已经完成了你所说的,但仍然没有......萤火虫中没有 ajax 请求。请检查我编辑的问题描述代码