我正在使用jsTree,并且有2个文本框:
<input type="text" id="previous_tree_id" value="" /><hr />
<input type="text" id="current_tree_id" value="" />
在jsTree回调中,我有:
$("#demo_1").tree({
callback : {
onselect : function (NODE, TREE_OBJ) {
var selected_tree_id = $(NODE).attr('id');
$("#current_tree_id").val(selected_tree_id);
}
}
});
我的问题是
如何将先前选择的树项的ID放入previous_tree_id文本框中?我的树号只是数字,我有3个树项。
树ID:1、2、3
因此,例如,如果有3个树项目,而我首先选择第一个树项目,则:
行动:
-选择树ID 1
输出:
-文本框previous_tree_id = 1
-文本框current_tree_id = 1
然后,我将选择树ID 2:
行动:
-选择树ID 2
输出:
-文本框previous_tree_id = 1
-文本框current_tree_id = 2
然后,我将选择树ID 3:
行动:
-选择树ID 3
输出:
-文本框previous_tree_id = 2
-文本框current_tree_id = 3
只是我必须解决的JavaScript逻辑,还是缺少一些jsTree函数来获取参考/先前选择的树项目?
提前致谢。
-马克
最佳答案
在jojo的帮助下解决了问题。
$("#demo_1").tree({
callback : {
onselect : function (NODE, TREE_OBJ) {
var selected_tree_id = $(NODE).attr('id');
// update first the previous_tree_id textbox
$("#previous_tree_id").val(current);
// store the new selected tree id in the current_tree_id
$("#current_tree_id").val(selected_tree_id);
}
}
});
关于javascript - jsTree:如何获取先前选择的树节点ID?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2972119/