JsTree打开一个节点,然后选择一个子节点(使用json_result) [英] JsTree Open a node then select a child node (using json_result)
问题描述
我有我使用在MVC2项目JsTree麻烦。我想创建一个函数来取消/关闭树上的所有节点。然后打开一个特定的节点,然后选择特定的子节点(我有ID值两者)。
I am having trouble with a JsTree I am using in an MVC2 project. I would like to create a function to deselect/close all nodes on the tree. Then open a specific node, and select a specific child node (I have the Id values for both).
麻烦的是,select_node是open_node完成之前总是叫,所以节点没有选择,因为树没有加载的数据还没有,和节点ID不存在。
The trouble is that the select_node is always called before the open_node finishes, so the node is not selected, as the tree has not loaded the data yet, and the node ID does not exist.
我第一次尝试这个功能。
I first tried this function.
$('#demo3').jstree('deselect_all');
$('#demo3').jstree('close_all');
$('#demo3').jstree("open_node", $('#ParentId'), false, true);
$('#demo3').jstree("select_node", $('#ChildId'));
我又试图移动code到select_node和树move_node绑定,但没有运气。目前我使用的setTimeout(),这是一个可怕的解决方案卡住了。
I then tried moving the code to the select_node and move_node binds of the tree, but no luck. At the moment I'm stuck using a setTimeout(), which is a horrible solution.
有谁知道我可以告诉树,只选择开盘节点完成后?
Does anyone know how I can tell the tree to only select the node after opening has finished?
推荐答案
您可以尝试通过它选择的节点像一个回调函数:
You could try passing a function that selects the node as a callback like:
$('#demo3').jstree('open_node', '#ParentID', function(e, data) {
$('#demo3').jstree('select_node', '#ChildId');
}, true);
一旦open_node返回成功
本办法 select_node
将被调用。
This way select_node
will be called once the open_node returns success.
这篇关于JsTree打开一个节点,然后选择一个子节点(使用json_result)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!