【问题标题】:Filter SiteTree TreeDropdownField() in SilverStripe 3.1在 SilverStripe 3.1 中过滤 SiteTree TreeDropdownField()
【发布时间】:2015-03-20 16:34:55
【问题描述】:

如何过滤SiteTree 页面的结果,以便只得到一个ClassName 为ProductPage 的页面?

这里是相关的代码部分-

static $has_one = array('ProductLinkPagesID' => 'SiteTree');

这里

$ProductLinkPages = new TreeDropdownField('ProductLinkPagesID', 'Related Products Link', 'SiteTree');

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    如果您确实想保留树结构,但只允许人们选择“ProductPage”页面,您可以使用 TreeDropdownField 并禁用所有其他节点:http://api.silverstripe.org/3.1/class-TreeDropdownField.html#_setDisableFunction

    $tree->setDisableFunction(function($item) {
        return ( ! $item instanceof ProductPage);
    });
    

    【讨论】:

      【解决方案2】:

      因为需要的结果来自 SiteTree 是页面但只有一种类型的页面 - ProductPage,这里使用 DropdownFieldProductPage::get()->map() 更好 -

      $ProductLinkPages = DropdownField::create('ProductLinkPagesID', 'Related Products Link', ProductPage::get()->map());
      

      感谢用户 4694959

      【讨论】:

        【解决方案3】:

        TreeDropdownField 如果被过滤,则无法呈现树。

        您需要使用原版 DropdownField - 或其他解决方案,如果您发现数字太大而无法通过下拉列表进行拖网搜索。尽管默认情况下 CMS 使用 jquery.chozen 来帮助解决这个问题。

        【讨论】:

        • 非常感谢,DropdownField 在这里与 ProductPage::get()->map() 一起使用会更好
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-23
        • 2014-04-27
        相关资源
        最近更新 更多