Use parents
in jQuery to get all parents, filtering out by li
because all tree items are li
in jstree
, try this:
var parents = data.rslt.obj.parents("li");
And for children use children
in jQuery, like so:
var children = data.rslt.obj.parent().find('li');
EDIT Using the above, here's how to get all parent and children and put them in all an array for each:
Parents:
var parents = [];
data.rslt.obj.parents("li").each(function () {
parents.push({ id: $(this).attr("id"), description: $(this).children("a").text() });
});
Children:
var children = [];
data.rslt.obj.find("li").each(function () {
children.push({ id: $(this).attr("id"), description: $(this).children("a").text() });
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…