大家好,
我正在尝试用几个列表框构建一个对话框窗口,每个列表框包含数据表中相应列的所有值。 在选择任何一个列表中的一个或多个项目之后,我希望其余列表中的项目根据该选择进行过滤。 我已经实现了下面刚刚描述的内容,但是事情是这样的:如果我以循环方式填充对话框窗口,而不是像下面那样用整数对列表子集索引进行硬编码,则函数的调用时间为i的当前值。执行,而不是在循环中创建列表框时使用的值。 我已经阅读了脚本指南,并尝试了几个选项,包括Eval(Eval Expr(Expr()))和Eval Substitute(Expr(),Expr())),但我无法使其正常工作。 我现在打算将整个表达式构建为循环中的长字符串,并对其进行Eval(Parse())的处理,但这似乎很愚蠢。 有人可以在这里为我提供正确的语法吗?
谢谢,
约翰
Names Default To Here( 1 );
If( !Namespace Exists( "fq" ),
New Namespace(
"fq"
)
);
dt = New Table( "Sample data",
Add Rows( 9 ),
New Column( "id",
Character,
"Nominal",
Set Values( {"a", "a", "a", "b", "b", "b", "c", "c", "c"} )
),
New Column( "value",
Character,
"Nominal",
Set Values( {"A", "B", "C", "D", "E", "F", "G", "H", "I"} )
),
New Column( "val2",
Character,
"Nominal",
Set Values( {"one", "two", "three", "one", "two", "three","one", "two", "three"} )
)
);
filterSelected = Function( {dt, values, index},
/*
Sorts displayed values in all list boxes based on selection
*/
columns = fq:filterColumns;
filters = fq:filters;
selectedColum = Remove From( columns, index )[1];
selctedFilter = Remove From( filters, index )[1];
rows = dt << Get rows where( Contains( values, as Column( dt, selectedColum ) ) );
// If nothing is selcted, all values should be chosen
If(Length(values)==0,
rows = dt << get rows where(!Ismissing(As Column(dt, selectedColum)))
);
// Set list items according to selection
Local( {j = 1},
For( j = 1, j <= N Items( filters ), j++,
filters[j] << Set items( Column( dt, columns[j] )[rows] )
)
);
);
getSelection = Function( {},
Local( {j =1},
For( j=1, j <= N Items(fq:filters), j++,
print(fq:filterColumns[j], fq:filters[j] << get items());
);
);
);
nestedFilters = Function( {filtercolumns},
fq:filtercolumns = filtercolumns;
dialog = New Window( "Fetch rows matching:",
Show Menu( 0 ),
show toolbars( 0 ),
Border Box( Top( 20 ), Bottom( 20 ), Left( 10 ), Right( 10 ),
V List Box(
Align( right ),
filter_boxes = V List Box(),
H List Box(
ok_button = Button Box( "OK" ),
cancel_button = Button Box( "Cancel", dialog << close window )
)
)
),
ok_button << Set function(
getSelection();
dialog << close window;
)
);
fq:filters = {};
fq:all_rows = {};
//for(i=1, i<=N Items(filtercolumns), i++,
filter_boxes << append( Text Box( fq:filtercolumns[1], <<SET font="" style=""></SET>尝试这个
for( i = 1, i <= N Items( filtercolumns ), i++,
eval(
evalexpr(
filter_boxes << append( Text Box( fq:filtercolumns[Expr( i )], <<SET font="" style=""></SET>我使用“ 1”的情况,将1更改为expr(i),将其放在eval / evalexpr中,在i循环中。
谢谢您的帮助! 不幸的是,我遇到了与过去相同的问题:当我在列表中进行选择时,如果i(即4)使用当前值调用filterSelected函数,导致下标范围错误。

我能做的就是这个,但这似乎... 我猜很傻...
expression = "";
for( i = 1, i <= N Items( fq:filtercolumns ), i++,
expression = expression ||
"filter_boxes << append( Text Box( fq:filtercolumns[" || char(i) || "], <<SET font="" style=""></SET>