簡體   English   中英

jsTree:如何獲取先前選擇的樹節點ID?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM