ツリーボックス内の要素の検索ツリー ボックス内の要素を検索することは可能ですか?
以下のリンクに示されている方法は、リスト ボックス内のユーザー入力要素を検索しますが、この方法はツリー ボックスには適用されません。
リストボックス内の要素の検索
これは、リストボックスではループを使って簡単にすべての項目を検索できるためです。ツリーボックス内の要素を検索するにはどのような方法がありますか?
次の 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: ツリーボックス内の要素の検索可能ですが、どのように探したいですか?見つかったら何をしたいですか?
例えば、ここで紹介した古いスクリプト「Directory Tree: Explore Space Used by Folders」 (私のgithub: jthi-jmp-tools/file-indexer (github))を見てください。ツリーボックスと検索ボックスを使っています。検索の他の例は、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: ツリーボックス内の要素の検索暗く表示は、検索キーワードに合致する項目を見分けるのに効果的ですが、子アイテムの数が多い場合、色を暗く表示するだけでは、検索結果に焦点を絞りにくくなる可能性があります。例えば、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 の代わりに、クローン作成などのディスプレイボックス構造のコピー方法を使用してください。すべてのノードが正しくクローン作成/コピーされ、同じオブジェクトを参照していないことを確認してください(コピーとディープコピーの違い)。
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));
),