<?php

use execut\widget\TreeView;
use yii\web\JsExpression;
$items = [['text' => 'Parent 1', 'nodes' => [['text' => 'Child 1', 'nodes' => [['text' => 'Grandchild 1'], ['text' => 'Grandchild 2']]], ['text' => 'Child 2']]], ['text' => 'Parent 2']];
$onSelect = new JsExpression(<<<JS
function (undefined, item) {
    console.log(item);
}
JS
);
$groupsContent = TreeView::widget(['data' => $data, 'size' => TreeView::SIZE_SMALL, 'clientOptions' => ['onNodeSelected' => $onSelect, 'selectedBackColor' => 'rgb(40, 153, 57)', 'borderColor' => '#fff']]);
<?php

use execut\widget\TreeView;
use yii\web\JsExpression;
$data = [['text' => 'Parent 1', 'nodes' => [['text' => 'Child 1', 'nodes' => [['text' => 'Grandchild 1'], ['text' => 'Grandchild 2']]], ['text' => 'Child 2']]], ['text' => 'Parent 2']];
$onSelect = new JsExpression(<<<JS
function (undefined, item) {
    console.log(item);
}
JS
);
$groupsContent = TreeView::widget(['data' => $data, 'size' => TreeView::SIZE_SMALL, 'header' => 'Categories', 'searchOptions' => ['inputOptions' => ['placeholder' => 'Search category...']], 'clientOptions' => ['onNodeSelected' => $onSelect, 'selectedBackColor' => 'rgb(40, 153, 57)', 'borderColor' => '#fff']]);
echo $groupsContent;
<?php

use yii\widgets\Pjax;
use yii\web\JsExpression;
use execut\widget\TreeView;
Pjax::begin(['id' => 'pjax-container']);
echo \yii::$app->request->get('page');
Pjax::end();
$onSelect = new JsExpression(<<<JS
function (undefined, item) {
    if (item.href !== location.pathname) {
        \$.pjax({
            container: '#pjax-container',
            url: item.href,
            timeout: null
        });
    }

    var otherTreeWidgetEl = \$('.treeview.small').not(\$(this)),
        otherTreeWidget = otherTreeWidgetEl.data('treeview'),
        selectedEl = otherTreeWidgetEl.find('.node-selected');
    if (selectedEl.length) {
        otherTreeWidget.unselectNode(Number(selectedEl.attr('data-nodeid')));
    }
}
JS
);
$items = [['text' => 'Parent 1', 'href' => Url::to(['', 'page' => 'parent1']), 'nodes' => [['text' => 'Child 1', 'href' => Url::to(['', 'page' => 'child1']), 'nodes' => [['text' => 'Grandchild 1', 'href' => Url::to(['', 'page' => 'grandchild1'])], ['text' => 'Grandchild 2', 'href' => Url::to(['', 'page' => 'grandchild2'])]]]]]];
echo TreeView::widget(['data' => $items, 'size' => TreeView::SIZE_SMALL, 'clientOptions' => ['onNodeSelected' => $onSelect]]);
示例#4
0
文件: index.php 项目: robky/tb
$nodeUnselected = new JsExpression(<<<JS
function (undefined, item) {
    if (item.href !== location.pathname) {
        \$.pjax({
            container: '#pjax-container',
            url: '',
            timeout: null
        });
    }
           //console.log(item);          

    
}
JS
);
$groupsContent = TreeView::widget(['data' => $data, 'header' => 'Объекты', 'searchOptions' => ['inputOptions' => ['placeholder' => 'Поиск объекта...']], 'clientOptions' => ['onNodeSelected' => $onSelect, 'onNodeUnselected' => $nodeUnselected, 'levels' => 1]]);
echo $groupsContent;
?>


</div>

<?php 
//Создание корня
Modal::begin(['header' => '<h3>Создание нового корня</h3>', 'id' => 'm_root']);
echo Html::beginForm(['root'], 'post');
echo Html::label('Введите название корня:', 'nametext');
echo Html::input('text', 'name', '', ['class' => 'form-control', 'id' => 'nametext']);
?>
<br/>
<?php