트리 상자에서 요소 검색트리 상자에서 요소를 검색하는 것이 가능합니까?
아래 링크에 표시된 방법은 목록 상자에서 사용자가 입력한 요소를 검색하지만, 이 방법은 트리 상자에는 적용되지 않습니다.
목록 상자에서 요소 검색
목록 상자는 루프를 사용하여 모든 항목을 쉽게 검색할 수 있기 때문입니다. 트리 상자에서 요소를 검색하는 데 어떤 메서드를 사용할 수 있나요?
다음 JSL은 간단한 트리 상자를 만드는 예입니다.
dt=New Table( "Food Tree",
Add Rows( 8 ),
New Column( "Name",
Character,
"Nominal",
Set Selected,
Set Values(
{"Apple", "Banana", "Watermelon", "Fruit", "Broccoli", "Lettuce",
"Potato", "Vegetable"}
)
),
New Column( "Category",
Character,
"Nominal",
Set Values(
{"Fruit", "Fruit", "Fruit", "", "Vegetable", "Vegetable", "Vegetable",
""}
)
),
New Column( "Level",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 2, 2, 1, 2, 2, 2, 1] )
),
Set Row States( [0, 0, 0, 1, 0, 0, 0, 0] )
);
relations = [=>];
For Each Row( dt,
relations[:Name] = Tree Node( :Name );
relations[:Name] <<SET data="https://community.jmp.com/"></SET>
<P><SPAN><BR /><BR /></SPAN></P><LINGO-LABS id="lingo-labs-867118" slang="en-US" mode="CREATE"><LINGO-LABEL>자동화 및 스크립팅</LINGO-LABEL></LINGO-LABS>Re: 트리 상자에서 요소 검색가능합니다. 어떻게 찾으시겠습니까? 찾으면 어떻게 하시겠습니까?
예를 들어, 제 github (jthi-jmp-tools/file-indexer(github)) 에 있는 "Directory Tree: Explore Space Used by Folders"라는 오래된 스크립트를 살펴보세요. 이 스크립트는 트리 박스를 사용하고 검색창도 있습니다. 다른 검색 예시는 JSL Function List 추가 기능 에서 찾을 수 있습니다. (요즘 Marketplace에 있을 것 같지만, 제가 Marketplace를 잘 사용하지 않아서 확실하지는 않습니다.)
Re: 트리 상자에서 요소 검색아래 그림과 같이 키워드를 입력하면 키워드와 일치하는 상품과 그 상위 상품만 표시되기를 바랍니다.
예를 들어, "물"을 입력하면 트리 상자에는 "수박"과 그 상위 항목인 "과일"만 표시됩니다.

Re: 트리 상자에서 요소 검색제가 제시한 예시를 살펴보셨나요?
Re: 트리 상자에서 요소 검색GitHub의 정보가 너무 복잡해요... 예시를 이해할 수 없고, 단서가 `search_tree` 함수에 있어야 한다는 것만 알고 있습니다.
좀 더 간단한 예를 들어주시겠어요?
Re: 트리 상자에서 요소 검색잎을 제거하지 않고도 숨길 수 있었는지는 기억나지 않지만 적어도 잎을 어둡게 할 수는 있습니다.
Names Default To Here(1);
root1 = Tree Node("Parent 1");
root2 = Tree Node("Parent 2");
c1 = Tree Node("Child 1");
c2 = Tree Node("Child 2");
c3 = Tree Node("Child 3");
c4 = Tree Node("Child 4");
root1 << Append(c1);
root1 << Append(c2);
root2 << Append(c3);
root2 << Append(c4);
nw = New Window("TreeBox",
tree = Tree Box({root1, root2}, Size(300, 200))
);
tree << Expand(root1);
tree << Expand(root2);
search_term = " 1";
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),
tree << make visible(cur_child);
is_hidden = 0;
,
cur_child << Set Dimmed(1);
);
);
If(is_hidden,
tree << Collapse(root);
,
tree << Expand(root);
);
);
얼마나 복잡한 트리를 가지고 있는지에 따라 재귀를 살펴보고 싶을 수도 있습니다.
Re: 트리 상자에서 요소 검색Dim은 항목이 검색 키워드와 일치하는지 구분하는 좋은 방법이지만, 하위 항목이 많은 경우 색상만 어둡게 하면 검색 결과에 집중하기 어려울 수 있습니다. 예를 들어, 1부터 100까지의 하위 항목 중에서 "1"이라는 키워드를 검색할 때, 1, 11-19, 100과 같이 일치하는 하위 항목을 함께 눈에 띄게 표시할 수 없습니다.
자식 옵션을 어둡게 하는 것보다 직접 숨길 수 있다면 더 좋을 것 같습니다.
현재 dim처럼 일치하지 않는 자식 항목을 직접 숨길 수 있는 효과적인 방법이 있습니까?
Re: 트리 상자에서 요소 검색Scripting Index에서 Tree Box()와 Tree Node()에 대해 어떤 기능을 제공하는지 확인해 보셨나요? 제 기억이 맞다면, Tree Box()에서는 노드를 숨길 수 없으므로, 노드 수를 줄여서 트리를 다시 만드는 다른 방법을 사용해야 합니다. 그렇게 어렵지는 않지만, 추가적인 JSL과 매개변수 관리가 필요합니다.
Re: 트리 상자에서 요소 검색노드를 제거해서 진행하고 싶습니다. 키워드가 변경될 때마다 노드를 다시 제거해야 합니다. 예를 들어, JSL에서 첫 번째 키워드는 1이고, 그다음에는 2로 변경되지만 항상 오류가 발생합니다. 왜 그럴까요? 이 논리에 따르면 어떻게 수정해야 할까요?
Names Default To Here(1);
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);
nw = New Window("TreeBox",
vlb = V List Box();
);
search_term = " 1";
tree = Tree Box({root1, root2}, Size(300, 200));
tree << Expand(root1);
tree << Expand(root2);
treeDuplicate=tree;
For Each({root}, treeDuplicate << 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,
treeDuplicate << Collapse(root);
,
treeDuplicate << Expand(root);
);
);
vlb << append(treeDuplicate );
wait(3);
treeDuplicate<< delete;
wait(3);
search_term = " 2";
treeDuplicate=tree;
For Each({root}, treeDuplicate << 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,
treeDuplicate << Collapse(root);
,
treeDuplicate << Expand(root);
);
);
vlb << append(treeDuplicate );
Re: 트리 상자에서 요소 검색트리를 삭제하면 더 이상 접근할 수 없습니다. duplicate = tree 대신 복제나 다른 방법으로 디스플레이 상자 구조를 복사하세요. 모든 노드가 올바르게 복제/복사되고 있는지, 그리고 동일한 객체를 참조하지 않는지(복사 vs. 깊은 복사) 확인해야 합니다.
Names Default To Here(1);
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);
nw = New Window("TreeBox",
vlb = V List Box();
);
tree = Tree Box({root1, root2}, Size(300, 200));
tree << Expand(root1);
tree << Expand(root2);
treeDuplicate = tree;
treeDuplicate1 = tree << clone box;
show(
treeDuplicate == tree,
treeDuplicate1 == tree,
treeDuplicate << get roots == tree << get roots,
treeDuplicate1 << get roots == tree << get roots
);
treeDuplicate == tree = 1;
treeDuplicate1 == tree = 0;
treeDuplicate << get roots == tree << get roots = 1;
treeDuplicate1 << get roots == tree << get roots = 1; // be careful here
Re: 트리 상자에서 요소 검색의미는 Clone Box 방법을 사용하더라도 복사된 트리 노드가 제거되면 원본 트리와 그 루트도 제거된다는 사실을 피할 수 없다는 것을 암시하는 것 같습니다.
즉, 키워드가 변경될 때마다 새로운 트리를 구축하고 키워드와 일치하는 노드를 제거해야 합니다. 결과적으로 노드가 많으면 키워드 검색에 계산 시간이 매우 많이 소모됩니다.
원본 나무의 완전히 독립적인 사본을 만드는 대체 방법이 있습니까?
Re: 트리 상자에서 요소 검색트리 상자를 탐색하여 "수동으로" 복사본을 생성하거나(트리를 순환하며 복사본을 생성), 다른 데이터 구조(예: 데이터 테이블/연관 배열/사용자 정의 클래스)를 기반으로 복사본을 다시 생성할 수 있습니다. 또는 표현식/함수를 사용하여 이러한 문제가 발생하지 않도록 하는 방법이 있는지 확인해 볼 수 있습니다.
Re: 트리 상자에서 요소 검색매번 새로운 트리만 재생성할 수 있는 것 같습니다. 다음 JSL로 변경했는데, 키워드가 1일 때는 제대로 작동하지만 2, 4 또는 이와 비슷한 값을 입력하면 작동하지 않습니다. 문제가 무엇인지 알려주시겠어요?
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=""></SET>
<BR />Re: 트리 상자에서 요소 검색이 매우 빠른 예는 몇 가지 아이디어를 제공할 수 있습니다.
Names Default To Here(1);
initialize_tree = function({}, {Default Local},
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);
return(tree);
);
filter_itemsSensorListTree = Function({vlb, search_term}, {Default Local},
If(search_term != "",
new_tree = initialize_tree();
For Each({root}, new_tree << get roots,
For(i = root << Get Child Count, i >= 1 , i--,
cur_child = root << get child(i);
If(Contains(cur_child << get label, search_term),
new_tree << Make Visible(cur_child);
,
cur_child << remove;
);
);
If(root << Get Child Count == 0,
new_tree << remove root(root);
);
);
,
new_tree = initialize_tree();
);
vlb_new = V List Box(new_tree);
vlb << Inval;
(vlb << Child) << Delete Box();
vlb << Append(vlb_new);
vlb << Update Window;
);
nw = New Window( "TreeBox",
H List Box(
Icon Box( "SearchIndex" ),
Spacer Box( size( 5, 10 ) ),
item_search_teb_AllSensorTree = Text Edit Box("",
<<SET width=""></SET>
<P><CODE class=" language-jsl">
Re: 트리 상자에서 요소 검색다음 JSL로 변경해 보려고 했습니다. 노드를 선택한 후 버튼을 눌러 레이블 이름을 가져오고 싶습니다. 그런데 필터링 키워드를 입력한 후 트리에서 새 옵션을 선택하면 오류가 발생합니다. 아마도 `new_tree`가 로컬 변수이기 때문일 수 있습니다. 키워드 검색 후 새 트리에서 선택한 레이블을 가져오려면 어떻게 수정해야 할까요?
Names Default To Here( 1 );
initialize_tree = Function( {},
{Default Local},
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 );
Return( tree );
);
filter_itemsSensorListTree = Function( {vlb, search_term},
{Default Local},
If( search_term != "",
new_tree = initialize_tree();
For Each( {root}, new_tree << get roots,
For( i = root << Get Child Count, i >= 1, i--,
cur_child = root << get child( i );
If( Contains( cur_child << get label, search_term ),
new_tree << Make Visible( cur_child ),
cur_child << remove
);
);
If( root << Get Child Count == 0,
new_tree << remove root( root )
);
);
,
new_tree = initialize_tree()
);
vlb_new = V List Box( new_tree );
vlb << Inval;
(vlb << Child) << Delete Box();
vlb << Append( vlb_new );
vlb << Update Window;
);
nw = New Window( "TreeBox",
H List Box(
Icon Box( "SearchIndex" ),
Spacer Box( size( 5, 10 ) ),
item_search_teb_AllSensorTree = Text Edit Box( "",
<<SET width=""></SET>Re: 트리 상자에서 요소 검색버튼 상자가 참조하는 트리가 삭제되어 잘못된 표시 상자를 참조하고 있습니다. 참조를 업데이트하는 좋은 방법이 있지만, 참조를 동적으로 만들어 VLB 내에서 항상 최신 트리 상자를 찾을 수도 있습니다.
Button Box("Select",
label_selected = (vlb[TreeBox(1)] << get selected) << get label;
Try(ShowText << delete);
VLB2 << Append(ShowText = Text Box(label_selected));
),