sgu-infocom-official / yii2-widget-bootstraptreeview
yii2 的 Bootstrap Tree View 小部件包装器
dev-master
2022-11-29 12:15 UTC
Requires
- php: >=7.4
- execut/yii2-base: *
- npm-asset/sgu-bootstrap-treeview: @dev
- yiisoft/yii2: ~2.0.13
- yiisoft/yii2-bootstrap4: ~2.0.6
- yiisoft/yii2-jui: @dev
This package is not auto-updated.
Last update: 2024-09-23 13:39:25 UTC
README
安装
安装此扩展的首选方法是使用 composer。
安装
运行以下命令之一:
$ composer require sgu-infocom-official/yii2-widget-bootstraptreeview "dev-master"
或者添加
"sgu-infocom-official/yii2-widget-bootstraptreeview": "dev-master"
到你的 composer.json
文件的 require
部分。
简单示例
use sguinfocom\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...' ], 'clearButtonOptions' => [ 'title' => 'Clear', ], ], 'clientOptions' => [ 'onNodeSelected' => $onSelect, 'selectedBackColor' => 'rgb(40, 153, 57)', 'borderColor' => '#fff', ], ]); echo $groupsContent;
Pjax 导航示例
use yii\widgets\Pjax; use yii\web\JsExpression; use sguinfocom\widget\TreeView; use yii\helpers\Url; 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, ], ]);
更改小部件模板
您可以通过模板选项重新定义小部件模板
echo TreeView::widget([ ... 'template => TreeView::TEMPLATE_SIMPLE, //'template => TreeView::TEMPLATE_ADVANCED //by default ... ]);
支持的模板部分
许可证
yii2-widget-bootstraptreeview 采用 Apache License Version 2.0 发布。有关详细信息,请参阅附带的 LICENSE.md
文件。