-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsTree.php
More file actions
34 lines (28 loc) · 766 Bytes
/
JsTree.php
File metadata and controls
34 lines (28 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* Created by PhpStorm.
* User: johnny
* Date: 17-6-16
* Time: 上午12:04
*/
namespace johnnylei\jstree;
use yii\base\Exception;
use yii\base\Widget;
use yii\helpers\Json;
class JsTree extends Widget
{
public $containerId = 'js-tree';
public $options;
public $enableInitialJs = true;
public $js;
public function run() {
if (empty($this->options)) {
throw new Exception('options is required');
}
JsTreeAsset::register($this->view);
$initial_js = $this->enableInitialJs?
'$("#'.$this->containerId.'").jstree('.Json::encode($this->options).');':'';
$this->view->registerJs($initial_js . $this->js);
return '<div id="'.$this->containerId.'"></div>';
}
}