1

我使用“perPage”选项创建了我的组件,该选项接受一个数字并设置每页作品显示的限制......

在此处输入图像描述

public function defineProperties()
    {
        return [
            'perPage' => [
                'title' => 'Number os works per page',
                'description' => 'How many works do you want to display per page?',
                'default' => 9,
                'validationPattern' => '^[0-9]+$',
                'validationMessage' => 'Only numbers allowed'
            ],
            'sortOrder' => [
                'title' => 'Order of Works',
                'description' => 'How do you want to order the actors',
                'type' => 'dropdown',
                'default' => 'newest',
            ],
        ];
    }

使用 GET 实现效果很好......但是在我的项目中我需要在任何地方实现 AJAX,所以我需要通过 AJAX 加载页面,并且我需要知道在组件上设置的数字是什么......我怎么能得到这个数字?

//my layout code
function onOpenWorkList()
{

    $this['works'] = Category::where('slug', input('slug'))->first();

    $this['categories'] = Category::all();

    $this['active_category'] = input('slug');

    $this['perPage'] = "";  // HERE IS THE CODE

    return [
        '.home_categories' => $this->renderPartial('work_list_categories_post'),
        '.container' => $this->renderPartial('work_list')
    ];
}

在此处输入图像描述

4

2 回答 2

0

在您的组件文件中:

public $perPage;

/* ... */

public function init()
{
    $this->perPage = $this->property('perPage');
}

然后,在布局中,您可以这样做:

function onOpenWorkList()
{
    $this['works'] = Category::where('slug', input('slug'))->first();

    $this['categories'] = Category::all();

    $this['active_category'] = input('slug');

    $_component = $this->components['builderList']; // Get the component

    $this['perPage'] = $_component->perPage; // Get $perPage from component

    return [
        '.home_categories' => $this->renderPartial('work_list_categories_post'),
        '.container' => $this->renderPartial('work_list')
    ];
}

就个人而言,我只是将onOpenWorkList()函数放入组件文件(而不是布局代码中),因为它仍然可以通过 ajax 访问,当它在那里时,你不必像在上面的例子。

于 2017-03-11T11:31:40.980 回答
0

从 PHP 区域的 Builder 组件获取属性,应该在 onEnd 函数中使用:

    function onEnd()
    {
        $component = $this->page->components['builderDetails']->record
    }
于 2018-09-12T21:46:46.397 回答