- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 JSTree 和 Ajax 方面遇到了一个奇怪的问题。
我通过 Ajax/PHP 请求生成我的树,该请求使用...生成 HTML(带有 UL、LI、A 标签)
$.ajax({
url: 'ajaxTreeView.php?method=edit&partid='+partId,
cache: false,
success: function(tree)
{
$('#treeViewer').html(tree);
}});
并使用...激活代码上的 JStree
options =
{
"core": { animation: 120 },
"themes": { theme: 'corral', dots: true },
"types":
{
"types":
{
"parent": { "icon": { "image": "images/custom/Legend/node_select.png" } },
"child": { "icon": { "image": "images/custom/Legend/node_select_child.png" } },
"current": { "icon": { "image": "images/custom/Legend/node.png" } }
}
},
"plugins": [ "html_data", "types", "themes", "ui", "contextmenu", "cookies" ],
"ui": { "select_limit" : 1 },
"cookies": { "save_selected" : false }
};
$("#tree").jstree(options);
我似乎无法轻松选择节点。我尝试了initial_select,但这似乎不起作用,而且也不理想,因为我经常想以编程方式选择节点。
我尝试使用...
$('#tree').jstree("select_node", '#ref565', true);
如果我通过超链接调用该函数,则此方法有效,但如果我在初始化 JStree 后调用该函数,则此方法无效。
我通过添加警报看到(所有这一切都发生在 Ajax Success 例程中)...
$('#treeViewer').html(tree);
$("#tree").jstree(options);
alert('test');
$('#tree').jstree("select_node", '#ref565', true);
...在警报开始之前树尚未渲染。
我添加了一个setTimeOut...
$('#treeViewer').html(tree);
$("#tree").jstree(options);
setTimeout(function() {selectNode(565);},1250);
$('#tree').jstree("select_node", '#ref565', true);
...这有效。
我显然是愚蠢的。我使用了错误的语法吗?为什么我必须设置延迟才能选择节点?
请帮忙。
最佳答案
如果您想在树加载后最初选择某些节点,则应该使用 initially_select
ui 的选项插入。您说您尝试过,但我没有看到您发布的示例代码中使用了它。您确定提供的 ID 正确吗?
要以编程方式选择节点,您需要等待要选择的节点首先出现在 DOM 中。我猜测绑定(bind)到 loaded.jstree 事件更正确,而不是使用超时回调,该事件应该在树完成加载并且所有树元素都在DOM,并在其中进行编程选择。
显示用法的示例代码:
$(function () {
$("#tree")
.jstree({
// List of active plugins
"plugins" : [
"ui"
],
// UI & core - the nodes to initially select and open will be overwritten by the cookie plugin
// the UI plugin - it handles selecting/deselecting/hovering nodes
"ui" : {
// this makes the node with ID node_4 selected onload
"initially_select" : [ "#ref565" ]
},
// the core plugin - not many options here
"core" : {
// just open those two nodes up
// as this is an AJAX enabled tree, both will be downloaded from the server
"initially_open" : [ "#ref565" ]
}
})
.bind("loaded.jstree", function (e, data) {
$('#tree').jstree("select_node", '#ref565', true);
})
});
关于jquery - JS 树 - select_node 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12817715/
我有一个 jstree,其中我使用 select_node 事件来切换节点(展开),因此删除了树中的切换箭头,因为它们看起来很难看,而且我不需要它们。 现在我已经添加了要在树中使用的复选框插件,但发现
我创建了一个 select_node 事件。但是当我们选择一个节点时它会触发两次。在这里,您可以看到我在 select_node 事件上设置的更改,该事件触发了两次。 还在 JStree 初始化中我指
我在 JSTree 和 Ajax 方面遇到了一个奇怪的问题。 我通过 Ajax/PHP 请求生成我的树,该请求使用...生成 HTML(带有 UL、LI、A 标签) $.ajax({ url:
我正在尝试找到一种方法,可以在加载动态上下文菜单(右键单击)时抑制 jstree 中的 changed 事件。我知道你可以 suppress the select_node event在上下文菜单中,
我正在使用 jstree 并且 select_node.jstree 不会触发,这是代码 $(document).ready(function () { //$("#MySplitter").spli
我有 jsTree 和一个按钮。 jsTree有select_node函数 .bind("select_node.jstree", function (event, data) { // some
如何在 select_node 事件上为 jstree 添加元数据。这就是我要添加的方式: $.ajax({ type : 'GET', url : '/asse
我有一个 jsTree,当用户点击一个节点时,它会触发 select_node 事件。但是,我还有一个列表,其中包含一些带有 jsTree 中节点 ID 的条目。在这个列表中选择一个条目时,我只需要从
当你打开节点时,没问题。不调用“select_node.jstree”。但是,当您选择一个节点然后关闭其父节点时,jstree 会出于某种奇怪的原因为该父节点触发“select_node.jstree
当我单击网站上的 jsTree 节点时,出现“未捕获类型错误:无法读取未定义的属性‘obj’”。 单击节点后,jsTree 应使用键检索值,将其保存到表单,然后提交表单。这就是我的 JSON 中“at
我是一名优秀的程序员,十分优秀!