表列表:如何交互式更新而不丟失選擇我看過有關此主題的討論,但找不到解決方案。
問題如下:
我正在處理列錶框中顯示的表格列表。 我使用 N Table() 方式獲取所有表的名稱列表。
我想要的是,如果我單擊選擇該列表中的任何行 - 列表本身會更新並檢查是否有新打開的表或某些表已關閉。
這樣做的好方法是每次單擊選擇時使用設置項目(openDTs)。 它很好地更新了表列表 - 問題是它刪除了選擇。
如果我在列錶框中使用 Append(openDTs) - 它會添加打開的任何新表,但如果我關閉表,它不會刪除已關閉的表。
更新表列表的最優雅和最正確的方法是什麼,在列表上單擊時反映打開和關閉的表,以便保留選擇?
回复:表列表:如何交互式更新而不丟失選擇米格羅,
Kevin Anderson 在此鏈接的討論中發布了我們的書《JSL Companion》第二版中的腳本
比較列表但不包含部分字符串
因此,我的建議是修改您的第一個函數,該函數返回列錶框中所選項目的列表。 然後將 Lfunc() 函數與 contains 一起使用,或使用交集函數來查找所選列表與 ctbls(當前表的列表)的交集。 結果列表將是您需要選擇的列表。 該鏈接描述了一種使用關聯數組來查找交集的簡單技術,或者查看第 5 章中的附加腳本:函數uniq_intersect(ctbls, selllist) 。
我希望這是清楚的。 昨天我沒有添加更多內容,因為你的其他功能非常接近。
回复:表列表:如何交互式更新而不丟失選擇謝謝,格魯吉亞!
這絕對是一種獲得最新表列表的更優雅的方式。 唯一的小問題是 - 使用所選項目更新列錶框而不丟失選擇的最佳方法是什麼?
回复:表列表:如何交互式更新而不丟失選擇米格羅,
如果您使用的是 JMP 14,則有一個新命令 Get Data Table List() 可返回打開的數據表的列表。 如果您不使用 JMP 14,則需要 N Table() 命令。
另外,“訂閱數據表列表”(<訂閱者>, OnOpen() | OnClose() | OnRename() ) 在 JMP 12、13,14 上可用。
下面是一個探索表訂閱的腳本。 請注意,您可以在每次更改時更新列表,而不是顯示 ctbls。
最後注意,NTable() 會“計算”不可見數據表,但私有數據表不計算在內。
Names Default To Here( 1 );
//---Use one of these functions
//---- JMP 14 function
//ctbls = Get Window List( Type("DataTables")) << Get Window Title();
// --- User function to returns a list of table names
curtbl_fn = Function({}, {nt, tlist={}, i},
nt= NTable();
If(nt >0,
For(i=1, i<=nt, i++,
Insert into(tlist, Data Table(i) << get name)
);
); // end if
tlist
); //end Function
//------ functions to handle when a new table is created, whe a table is renamed and when a table is closed.
fnew = Function( {dtab},
Insert Into(ctbls, dtab << Get Name );
show(ctbls, NTable())
);
fnnme = Function( {dtab, b},{i},
show(dtab, b);
i = contains(ctbls, b );
If (i>0, ctbls[i] = dtab << get name);
show(ctbls, NTable())
);
fclose = Function( {dtab}, {i},
i = contains(ctbls, dtab<<GET name="">0, remove from(ctbls, i));
show(ctbls, NTable());
);
Open("$Sample_Data/Variability Data/2 Factors Crossed.jmp");
Open("$Sample_Data/Baseball.jmp");
Open("$Sample_Data/Basketball.jmp");
Open("$Sample_Data/Football.jmp");
Open("$Sample_Data/Fishing.jmp");
Open("$Sample_Data/Pogo Jumps.jmp");
//_____________________________________________________________________
//--- Run to here ------------------------
//use the JMP 14 command or the functions
ctbls =curtbl_fn();
show(ctbls, NTable());
//--- Run to here and check the log------------------------
aSub = Subscribe to Data Table List( , OnOpen( fnew ) );
Subscribe to Data Table List( aSub, OnRename( fnnme ) );
Subscribe to Data Table List( aSub, OnClose( fclose ) );
dt = Open( "$SAMPLE_DATA/Iris.jmp" );
Wait( 2 );
dt << setname( "yyy" );
// two printouts: one for OnOpen() and one for OnRename()
//--- Run to here and check the log------------------------
Close(Data Table("Fishing"), NoSave);
//--- Run to here and check the log------------------------
//Check Table manipulations
Data Table("yyy") << Subset (All Rows, All Columns, Output Table Name ("Iris redux") );
//--- Run to here and check the log------------------------
Unsubscribe to Data Table List(asub, All);
print("should not do anything");
Close(Data Table("Baseball"), NoSave);</GET>
回复:表列表:如何交互式更新而不丟失選擇現在我是這樣解決的:
我記住所選表的名稱,然後使用 Set Items 完全重寫,然後迭代整個列表並將記住的名稱與新列表進行比較(順序,因此 indeces 現在可能不同!)。 一旦我點擊相同的名稱,我就會記住該索引並使用該索引進行設置。
這是代碼:
listofTablesSelect=Function({this},{selectedIndex},
// This function is called when the List Box selection changes
selectedIndex = this << Get Selected;
selectedTableName = selectedIndex[1];
refreshListofTables();
for (i=1, i<=N Items(listofTablesList = this<<GET items=""></GET>其中refreshListofTables使用Set Items:
refreshListofTables = Function({},
Show("Trying to refresh list of tables");
openDTs = List();
For( i = 1, i <= N Table(), i++,
Insert Into( openDTs, Data Table( i )<<GET name=""></GET>我唯一不喜歡的事情是:日誌窗口顯示“JSL 遞歸被阻止”——遞歸到底在哪裡? 是
this << Set Selected(recallIndex);
有效地調用整體
refreshListofTables
再次,因此進入遞歸?
有辦法解決嗎?
塔克斯,
中號