efureev/ yii2-bootstraptreeview
此包已被废弃且不再维护。没有建议的替代包。
yii2的Bootstrap Tree View小部件包装器
1.0.3
2015-10-13 13:56 UTC
Requires
- bower-asset/efureev-bootstrap-treeview: *
- yiisoft/yii2-jui: *
This package is auto-updated.
Last update: 2021-06-29 00:58:17 UTC
README
安装
安装此扩展的首选方式是通过composer。
安装
运行以下命令之一
$ php composer.phar require efureev/yii2-widget-bootstraptreeview "dev-master"
或者将以下内容添加到您的composer.json
文件的require
部分:
"efureev/yii2-widget-bootstraptreeview": "dev-master"
to the require
section of your composer.json
file.
简单示例
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', ], ]);
Pjax导航示例
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', 'def' => 'Description', 'href' => Url::to(['', 'page' => 'parent1']), 'nodes' => [ [ 'text' => 'Child 1', 'href' => Url::to(['', 'page' => 'child1']), 'tags' => [12], 'nodes' => [ [ 'text' => 'Grandchild 1', 'href' => Url::to(['', 'page' => 'grandchild1']) ], [ 'text' => 'Grandchild 2', 'href' => Url::to(['', 'page' => 'grandchild2']) ] ] ], ], ], ]; $onNodeHover = new \yii\web\JsExpression(<<<JS function (undefined, item, tv) { item.def = 'Description'; tv.treeview('redrawNode', item); } JS ); $onNodeLeave= new \yii\web\JsExpression(<<<JS function (undefined, item, tv) { delete item.def; tv.treeview('redrawNode', item); } JS ); echo TreeView::widget([ 'data' => $items, 'size' => TreeView::SIZE_SMALL, 'clientOptions' => [ 'onNodeSelected' => $onSelect, 'showTags' => true, 'showTips' => true, 'onNodeSelected' => $onSelect, 'onNodeHover' => $onNodeHover, 'onNodeLeave' => $onNodeLeave, ], ]);
许可证
yii2-widget-bootstraptreeview是在Apache License Version 2.0下发布的。有关详细信息,请参阅附带LICENSE.md
文件。