yii-dream-team / yii2-jstree

Yii2 jsTree component
http://yiidreamteam.com/yii2/jstree
30 stars 7 forks source link

Subscribe to events thru PHP code #7

Open khvalov opened 5 years ago

khvalov commented 5 years ago

As workaround you can subscribe to JSTree events using approach:

$this->registerJs('
        $("#w1").on("changed.jstree", function (e, data) {
          console.log(data.selected);
        });
    ');

but it will be better to use solid approach like:

'jsOptions' => [
            'core' => [
                'multiple' => true,
                'data' => $tree,
            ],
            "checkbox" => [
                "keep_selected_style" => false
              ],
            "plugins" => [ "wholerow", "checkbox" ],
             "events" => ['changed.jstree'=>new JsExpression('function (e, data) {
          console.log(data.selected);
        }')],

        ]