File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 28
28
Once the extension is installed, simply use it in your code by :
29
29
30
30
``` php
31
- <?= \lesha724\bootstraptree\TreeView::widget(); ?>```
31
+ <?= \lesha724\bootstraptree\TreeView::widget([
32
+ 'htmlOptions'=>[
33
+ 'id'=>'treeview-tabs'
34
+ ],
35
+ 'options'=>[
36
+ 'data'=>$items,
37
+ 'enableLinks'=>true,
38
+ 'showTags'=>true,
39
+ 'levels'=>3
40
+ ],
41
+ 'events'=>[
42
+ 'onNodeSelected'=>'function(event, data) {
43
+ // Your logic goes here
44
+ alert(data.href);
45
+ }'
46
+ ]
47
+ ]); ?>
48
+ ```
Original file line number Diff line number Diff line change 3
3
namespace lesha724 \bootstraptree ;
4
4
use yii \helpers \Html ;
5
5
use yii \helpers \Json ;
6
+ use yii \web \JsExpression ;
6
7
use yii \web \View ;
7
8
8
9
/**
@@ -20,6 +21,11 @@ class TreeView extends \yii\base\Widget
20
21
*/
21
22
public $ options =[];
22
23
24
+ /**
25
+ * @var array additional options that can be passed to the constructor of the treeview js object.
26
+ */
27
+ public $ events =[];
28
+
23
29
protected $ _id ;
24
30
25
31
public function init (){
@@ -38,12 +44,26 @@ public function run()
38
44
$ view = $ this ->getView ();
39
45
TreeViewAsset::register ($ view );
40
46
41
- $ options =$ this ->options ===[]?'{} ' : Json::encode ($ this ->options );
47
+ $ options = $ this ->_getEventsOptions ();
48
+ $ options =$ options ===[]?'{} ' : Json::encode ($ options );
42
49
$ view ->registerJs ('$("# ' . $ this ->_id . '").treeview( ' .$ options .') ' , View::POS_READY );
43
50
44
51
return $ this ->_runWidget ();
45
52
}
46
53
54
+ /**
55
+ * @return array the javascript options
56
+ */
57
+ protected function _getEventsOptions ()
58
+ {
59
+ $ options =$ this ->options ;
60
+ foreach ($ this ->events as $ key =>$ event )
61
+ {
62
+ $ options [$ key ]=$ _function = new JsExpression ($ event );
63
+ }
64
+ return $ options ;
65
+ }
66
+
47
67
/**
48
68
* Вывод виджета
49
69
* @return string html widget
You can’t perform that action at this time.
0 commit comments