银条3过滤器阵列列表



我们如何在 Silverstripe 3 中过滤 ArrayList?

其中 getVideosfromCategories(( 返回一个合并的 ArrayList

我需要这样的东西:

$this->getVideosfromCategories()->filter('ID:LessThan', $id)->sort(array('ID' => 'DESC'))->first()

这些过滤器(过滤器('ID:LessThan', $id((仅适用于数据列表?

如何过滤我的数组列表?

这些过滤器(filter('ID:LessThan', $id((仅适用于DataList ?

是的,没错,搜索过滤器修饰符仅适用于DataList实例。 (https://docs.silverstripe.org/en/3/developer_guides/model/searchfilters/(有趣的是,文档没有提到这一点,我认为应该更新。

(我 https://github.com/silverstripe/silverstripe-framework/pull/9363 为它打开了一个公关(

但是您可以修改当前代码以按 ID 数组进行过滤,如下所示:

$idsWeWant = [];
if ($id > 0) {
$idsWeWant = range(0, $id - 1); // "$id - 1" because you had "LessThan" modifier.
}
$this->getVideosfromCategories()
->filter('ID', $idsWeWant)
->sort(array('ID' => 'DESC'))
->first();

最新更新