T
T
Tat622019-01-05 19:16:08
Yii
Tat62, 2019-01-05 19:16:08

How to get data from jstree-yii2 widget?

I am using JsTree widget from yiidreamteam. The tree is populated correctly on load. I need - after checking/unchecking when pressing a key, for example "save" get the data without using jscript. It can be in json format. How can I do it ? How to get data in actionIndex ? Something I'm confused. Tell me please.
view fragment:

........................................................................
<?= \yiidreamteam\jstree\JsTree::widget([
    'containerOptions' => [
        'class' => 'data-tree',
    ],
    'jsOptions' => [
        'core' => [
            'multiple' => true,
            'data' => [
               'url' => \yii\helpers\Url::to(['/site/jsonmy']), 
            ],
            'themes' => [
                'dots' => true,
                'icons' => false,
            ]
        ],
        'checkbox' => [
            'whole_node' => false, 
            'keep_selected_style' => true, 
            'three_state' => true,
            'tie_selection' => false
        ],
        'plugins' => [ "wholerow", "types", "checkbox"],
    ]
]) ?>   
..........................................................................
<div class="form-group">
         <?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary',]) ?> 
</div>

Controller snippet:
public function actionIndex()
    {
       return $this->render('index');
    }

public function actionJsonmy()
    {
        $json = '[
                {"id":"1","text":"Root node","state": {"opened":true},"children":[
                                                                        {"id":"2","text":"Child node 1","state":{"checked":true}},
                                                                        {"id":"3","text":"Child node 2","state":{"checked":true}}]}
        ]';
        Yii::$app->response->format = Response::FORMAT_JSON;
        $items = json_decode($json);

        return $items;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question