【发布时间】:2019-02-06 21:13:05
【问题描述】:
我正在尝试使用 GTK2::TreeModelFilter 过滤列表存储。我似乎无法在网上找到使用 perl 的示例,并且出现语法错误。有人可以帮助我使用下面的语法吗? $unfiltered_store 是一个列表存储。
$filtered_store = Gtk2::TreeModeFilter->new($unfiltered_store);
$filtered_store->set_visible_func(get_end_products, $unfiltered_store);
$combobox = Gtk2::ComboBoxEntry->new($filtered_store,1);
然后在下面的某个地方:
sub get_end_products {
my ($a, $b) = @_;
warn(Dumper(\$a));
warn(Dumper(\$b));
return true; # Return all rows for now
}
最终我要做的是查看listore ($unfiltered_store) 的第14 列,如果它是某个值,那么它会过滤到$filtered_store。
有人可以帮我解决这个问题的语法吗?我检查了一堆站点,但它们使用其他语言并使用不同的语法(例如“new_filter”——Perl GTK 不存在)。 这是我需要修复的最优雅的解决方案,我更愿意学习如何使用它,而不是使用暴力方法来提取和保存过滤后的数据。
【问题讨论】:
-
您需要传递对
get_end_products子例程的引用。所以试试$filtered_store->set_visible_func(\&get_end_products, $unfiltered_store) -
你的意思是这样? $filtered_store->set_visible_func(\&get_end_products, $unfiltered_store);
-
仅供参考,即使在通过引用传递之前,“get_end_products”函数也会被调用。我的问题与商店有关——如何在“get_end_products”功能中访问商店?两个 dumper 语句什么都不打印,但是在 get_end_products 函数中打印警告语句(如“Hello World”)确实有效。
-
嘿!我刚刚添加了参考并且......它有效!程序不会崩溃。真是太感谢你了。
-
很高兴听到!请注意,变量
$a和$b通常是sort函数使用的特殊变量。所以不推荐使用那些变量名。