Вопрос

can you please tell me how to get click event of li .I making li element dynamically using jstree . I am press add button it create a li element internally in jstree .can we get click event of that ? Press add two time.it generate li element.I want to get click event of li .get alert of its id.? http://jsfiddle.net/GS4u3/4/

$('#uu').click(function () {
var ref = $('#tree').jstree(true),
    sel = ref.get_selected();

if (!sel.length) {
    alert('thank')
    sel = ref.create_node("#", {"id" : node_count+1, "text" : node_count+1});
    node_count++;
} else
{
    sel = sel[0];
    sel = ref.create_node(sel, {"id" : node_count+1, "text" : node_count+1}); 
    node_count++;
}
/*if (sel) {
    ref.edit(sel);
}*/
ref.deselect_all();

});

Это было полезно?

Решение

This would do the job. Since the li is created dynamically, you need to delegate, which has been superseded by on.

$("#tree").on("click", "li > a", function() {
    var id = $(this).closest("li").attr("id");
    $(this).siblings(".jstree-icon").click();
    alert(id);
});

EDIT: Making only the text clickable and not the arrow.

EDIT2: http://jsfiddle.net/GS4u3/8/ (edit 4, new jsfiddle with your change updated)

EDIT3: Edited code, to expand the tree upon clicking the text.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top