, , , :
- "groupNodes", , groupNodes .
- , groupNodes.
- nodeId, , true false, childNodes.
- groupNodes, .
.
function binize(tree) {
var left,right,t,u,
stack=[tree];
while(t=stack.pop()) {
left=[];
right=[];
while(u=t.childNodes.pop()) {
(u.condition?left:right).push(u);
stack.push(u);
}
left.length&&t.childNodes.push({
groupNodeId:left[0].nodeId,
condition:true,
childNodes:left
});
right.length&&t.childNodes.push({
groupNodeId:right[0].nodeId,
condition:false,
childNodes:right
});
}
}
( , - , , ).
var tree={nodeId:'A',childNodes:[
{nodeId:'B',condition:true,childNodes:[]},
{nodeId:'C',condition:true,childNodes:[]},
{nodeId:'D',condition:false,childNodes:[
{nodeId:'F',condition:false,childNodes:[]},
{nodeIf:'G',condition:false,childNodes:[]}
]},
{nodeId:'E',condition:false,childNodes:[]}
]};
, . , , (, , ), .
, KnockoutJS , . , ; , .
user1000131