It seems that I can only regenerate a new tree each time. I changed it to the following JSL, and it works properly when the keyword is 1, but if I enter 2, 4, or something similar, it doesn't succeed. Could you please let me know what the problem might be?
root1 = Tree Node( "Parent 1" );
root2 = Tree Node( "Parent 2" );
c1 = Tree Node( "Child 1" );
c2 = Tree Node( "Child 2" );
c3 = Tree Node( "Child 11" );
c4 = Tree Node( "Child 4" );
filter_itemsSensorListTree = Function( {this, searchText},
{filtered_items, i},
// only attempt to filter if there is any text
If( searchText != "",
tree << delete;
search_term = searchText;
root1 = Tree Node( "Parent 1" );
root2 = Tree Node( "Parent 2" );
c1 = Tree Node( "Child 1" );
c2 = Tree Node( "Child 2" );
c3 = Tree Node( "Child 11" );
c4 = Tree Node( "Child 4" );
root1 << Append( c1 );
root1 << Append( c2 );
root2 << Append( c3 );
root2 << Append( c4 );
tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
For Each( {root}, tree << get roots,
is_hidden = 1;
For( i = 1, i <= root << Get Child Count, i++,
cur_child = root << get child( i );
If( Contains( cur_child << get label, search_term ),
is_hidden = 0,
cur_child << remove
);
);
If( is_hidden,
tree << Collapse( root ),
tree << Expand( root )
);
);
vlb << append( tree );
,
);
);
root1 << Append( c1 );
root1 << Append( c2 );
root2 << Append( c3 );
root2 << Append( c4 );
tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
tree << Expand( root1 );
tree << Expand( root2 );
nw = New Window( "TreeBox",
H List Box(
Icon Box( "SearchIndex" ),
Spacer Box( size( 5, 10 ) ),
item_search_teb_AllSensorTree = Text Edit Box( "",
<<set width( 150 ),
<<set text changed( filter_itemsSensorListTree )
),
reset_button_AllSensorTree = Button Box( "",
<<set icon( "DebuggerDeleteBreakpoint" ),
<<set script(
item_search_teb_AllSensorTree << set text( "" );
tree << delete;
root1 = Tree Node( "Parent 1" );
root2 = Tree Node( "Parent 2" );
c1 = Tree Node( "Child 1" );
c2 = Tree Node( "Child 2" );
c3 = Tree Node( "Child 11" );
c4 = Tree Node( "Child 4" );
root1 << Append( c1 );
root1 << Append( c2 );
root2 << Append( c3 );
root2 << Append( c4 );
tree = Tree Box( {root1, root2}, Size( 300, 200 ) );
tree << Expand( root1 );
tree << Expand( root2 );
vlb << append( tree );
),
<<set tip( "Clear filter" ),
),
Spacer Box( size( 5, 10 ) ),
),
vlb = V List Box( tree );
);