/** * Registers the needed JavaScript. */ public function registerClientScript() { $inputId = $this->options['id']; $jsTreeId = $this->getJsTreeId(); $options = $this->getClientOptions(); $options = empty($options) ? '' : Json::encode($options); $onChanged = ''; if ($this->onChanged) { $onChanged = ".on('changed.jstree', {$this->onChanged})"; } $onSelect = ''; if ($this->onSelect) { $onSelect = ".on('select_node.jstree', {$this->onSelect})"; } $view = $this->getView(); JsTreeAsset::register($view); $view->registerJs("\n jQuery('#{$jsTreeId}')\n .on('loaded.jstree', function() { jQuery(this).jstree('select_node', jQuery('#{$inputId}').val().split(','), true); })\n .on('changed.jstree', function(e, data) { jQuery('#{$inputId}').val(data.selected.join()); })\n {$onChanged}\n {$onSelect}\n .jstree({$options});\n "); }
/** * @inheritdoc */ public function init() { JsTreeAsset::register($this->getView()); $this->options['id'] = isset($this->options['id']) ? $this->options['id'] : $this->getId(); parent::init(); }