勇虎 / yii2-bootstrap-tree
适用于jonmiles bootstrap treeview 1.2.0和2.0.0(https://github.com/jonmiles/bootstrap-treeview)的bootstrap树
Requires
- php: >=5.5
- bower-asset/bootstrap-treeview: @dev
- yiisoft/yii2: *
- yiisoft/yii2-bootstrap: *
This package is not auto-updated.
Last update: 2024-09-29 01:23:37 UTC
README
为jonmiles bootstrap treeview(1.2.0
和2.0.0
)(https://github.com/jonmiles/bootstrap-treeview)提供bootstrap树。从dmitry-suffi/yii-tree-widget和lesha724/yii2-bootstrap-tree分支并改进而来。
特性
- 适用于jonmiles bootstrap treeview(
1.2.0
和2.0.0
)(https://github.com/jonmiles/bootstrap-treeview) - 根据路由/参数(例如
id
)自动显示选定的节点(例如:)
依赖
jonmiles bootstrap treeview 1.2.0
或2.0.0
(https://github.com/jonmiles/bootstrap-treeview)
安装
通过composer安装此扩展是首选方式。
运行以下命令:
php composer.phar require --prefer-dist yongtiger/yii2-bootstrap-tree "*"
或添加以下内容到您的composer.json文件的require部分:
"yongtiger/yii2-bootstrap-tree": "*"
配置
用法
data.$items结构示例(https://github.com/jonmiles/bootstrap-treeview#data-structure)
$items = [ [ 'text' => 'Node 1', ///(needed!) 'href' => ['site/index', id => 1], ///(optional) Note: `href` must be route array! 'icon' => 'glyphicon glyphicon-stop', ///(optional) 'selectedIcon' => "glyphicon glyphicon-stop", ///(optional) 'selectable' => true, ///(optional) 'state' => [ ///(optional) // 'checked' => true, // 'disabled' => true, // 'expanded' => true, // 'selected' => true, ], 'tags' => ['available'], ///(optional) 'visible' => true, ///(optional) same as [yii\widgets\Menu::$visible] 'encode' => true, ///(optional) same as [yii\widgets\Menu::$encode] // ... 'nodes' => [ ['text' => 'Node 1.1', 'href' => ['site/index', id => 2]], ['text' => 'Node 1.2', 'href' => ['site/index', id => 3]], ] ], [ 'text' => 'Node 2', 'href' => ['site/index', id => 4], 'nodes' => [ ['text' => 'Node 2.1', 'href' => ['site/index', id => 5]], ['text' => 'Node 2.2', 'href' => ['site/index', id => 6]], ] ], // ... ];
echo \yongtiger\bootstraptree\widgets\BootstrapTree::widget([ 'options'=>[ //https://github.com/jonmiles/bootstrap-treeview#options 'data' => $items, ///(needed!) 'enableLinks' => true, ///(optional) 'showTags' => true, ///(optional) 'levels' => 3, ///(optional) 'multiSelect' => true, ///(optional, but when `selectParents` is true, you must also set this to true!) ], 'htmlOptions' => [ ///(optional) 'id' => 'treeview-tabs', ], 'events'=>[ ///(optional) //https://github.com/jonmiles/bootstrap-treeview#events 'onNodeSelected'=>'function(event, data) { // Your logic goes here alert(data.text); }' ], ///(needed for using jonmiles bootstrap-treeview 2.0.0, must specify it as `<a href="{href}">{text}</a>`) 'textTemplate' => '<a href="{href}">{text}</a>', ///(optional) Note: when it is true, you must also set `multiSelect` of the treeview widget options to true! 'selectParents' => true, ]);
其他用法与yii\widgets\Menu相同。
-
textTemplate
与yii\widgets\Menu::labelTemplate相同注意:要使用
jonmiles bootstrap-treeview 2.0.0
,必须在treeview小部件选项中指定<a href="{href}">{text}</a>
-
encodeTexts
与yii\widgets\Menu::encodeLabels相同 -
selectNodes
与yii\widgets\Menu::activateItems相同 -
selectParents
与yii\widgets\Menu::activateParents相同注意:当为true时,您还必须将treeview小部件选项中的
multiSelect
设置为true! -
hideEmptyNodes
与yii\widgets\Menu::hideEmptyItems相同 -
route
与yii\widgets\Menu::route相同 -
params
与yii\widgets\Menu::params相同
注意
- 在jonmiles bootstrap-treeview 2.0.0中已弃用
href
。您可以在treeview小部件选项中指定textTemplate
为<a href="{href}">{text}</a>
来生成节点url。
文档
参考
另请参阅
待定
开发路线图
许可证
yii2-bootstrap-tree在MIT许可证下发布,有关详细信息,请参阅LICENSE文件。