问题
假设您提示用户做出选择。 当您从用户检索值时,它们通常存储在列表中。现在您需要选择与列表中的值匹配的数据。
解决方案
以下示例演示如何选择数据表中包含 JSL 列表中存储的任何值的行。 可以使用包含数值或字符串的列表,如下所示。有关详细信息,请参阅嵌入的注释。
/* Open a sample data table. */
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
/* Create a list of ages. */
myList = {9, 12, 15, 17, 18};
/* Select all rows which have an age that is in the list. */
dt << Select Where( Contains( myList, :age ) );
Wait( 2 ); // For demonstration purposes
/* Create a list of student names. */
myStudents = {"HENRY", "ROBERT", "BARBARA", "SALLY", "MARION"};
/* Select all rows which have any of the names in the list. */
dt << Select Where( Contains( myStudents, :name ) );
dt << Select Where( Any( Row() == Index( 3, 5 ) ) );
很酷 :)
有类似的东西吗
dt << Select Where( Any( :name == {"JANE", "DAVID","PATTY"}) );?
这难道不是您使用 Contains() 的目的吗?