october51371
october51371

Hi, given is the following component code:

{% set itemList = __SELF__.itemList %}
{% for item in itemList %}
    <div id="item-{{ item.id }}">
        {% partial __SELF__ ~ "::oneItem" item=item %}
    </div>
{% endfor %}

And the coressponding partial to render a single item:

<span>{{ item.title }}</span>
<button type="button"
    data-request="onChangeTitleOfOneItem"
    data-request-data="id: {{ item.id }}"
    data-request-update="'@oneItem': '#item-{{ item.id}}'">

Now the problem is, that i do not know how to return the changed item to the partial. The following code does not work.

public function onChangeTitleOfOneItem() {
    $id = post('id');
    $item = Item::find($id);
    $item->title = "Change title for testing purpose";
    return $item;
}

There is no error message, but the title won't update. Any ideas?

Thanks, Joachim

mjauvin
mjauvin

in onChangeTitleOfOneItem(), try assigning the item as a page/component variable and use this variable in the partial.

$this->page['item'] = $item;

Last updated

mjauvin
mjauvin

Actually, try pushing the partial update like so:

    return [
        '#item-' . $id => $this->renderPartial('oneItem', ['item' => $item])
    ];

1-3 of 3