[英]jsTree: How to get previously selected tree node ID?
我正在使用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);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.