Answer the question
In order to leave comments, you need to log in
Dynamic loading of yii\bootstrap\Collapse widget content?
I decided to display a "tree" list on YII2 using the yii\bootstrap\Collapse widget, since it collapses inactive branches by itself. The data is loaded from the database, the branching can be quite strong, and most importantly, the user in most cases will not view them at all, so I want to dynamically load the data to minimize the load on the server.
I hardly know JS and AJAX, I have already partially studied YII2, and it seems to me that somehow you can do everything with its means. Only the documentation shows how to dynamically replace data in views (PJAX), and I need to influence the content of the widget, respectively, and the html markup will change :)
That is, initially the following structure is rendered to the user:
Collapse::widget([
'items' => [
[
'label' => 'Список 1',
'content' => [],
],
[
'label' => 'Список 2',
'content' => [],
],
]
]);
Answer the question
In order to leave comments, you need to log in
first question: why did you decide that this option is less resource-intensive compared to building a full tree? Hiding child elements in Collapse. If the result of building a tree (html) is cached, this will be correct.
Now on the question:
after the Collapse widget has worked, you already have html, and arrays have nothing to do with it explicitly. Then we forget about php and work with jquery. You need to hook on the shown.bs.collapse event and send an ajax request to the server, form html there and return it, then insert it into the container.
bootstrap-3.ru/javascript.php#collapse
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question