gets the IDs of items in the currently opened group
object | the object with all parents to this level and an array of items from the currently opened group |
webix.ui({
view:"grouplist",
data:[ //hierarchical JSON dataset
{id:"root", value:"Films data", open:true, data:[
{ id:"1", open:true, value:"The Shawshank Redemption", data:[
{ id:"1.1", value:"Part 1" },
{ id:"1.2", value:"Part 2", data:[
{ id:"1.2.1", value:"Page 1" },
{ id:"1.2.2", value:"Page 1" }
]},
{ id:"1.3", value:"Part 3" }
]},
{ id:"2", open:true, value:"The Godfather", data:[
{ id:"2.1", value:"Part 1" }
]}
]}
});
var state = $$('grouplist1').getOpenState();
if (state){
result = JSON.stringify(state);
webix.message(result);
}
/*
If you open the "root" branch, there go to "1" and then open the "1.2"
{
"parents":["root","1","1.2"],
"branch":["1.2.1","1.2.2"]
}
*/
The return object contains two properties:
On the top level with all the groups closed, "parents" will be empty.
If you use non-hierarchical data and form groups (parents) on the go during component init, they get automatically generated IDs.
{
"parents":["1363185715932"], <- auto ID
"branch":[125,169,184,189]
}
If needed, every array can be accessed by an object key (e.g. branch to get items in the branch):
function get_children(){
var state = $$('group').getOpenState().branch; //gets only children
titles = [];
for (var i=0; i<state.length; i++){
var id = state[i];
var title = $$('group').getItem(id).title;
titles.push(title);
}
alert(titles.join(",\n")); //get all the titles of the children
}