1

我正在使用 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 文本框中?我的树 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 函数来获取参考/先前选择的树项?

提前致谢。- 标记

4

1 回答 1

1

在 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);
        }
    }
});
于 2010-06-04T08:16:38.563 回答