你好 我想用 jstree 自定义一个删除方法 配置如下:
<?= \yiidreamteam\jstree\JsTree::widget([
'containerOptions' => [
'class' => 'data-tree',
],
'jsOptions' => [
'core' => [
'check_callback' => true,
'multiple' => false,
'data' => [
// url获取分类接口
// [{"id" : 1, "text" : "服装", "children" : [{}, {}]}, {}]
'url' => \yii\helpers\Url::to(['project/categorytree', "page" => $page, "per-page" => $perpage]),
],
'themes' => [
"stripes" => true,
"variant" => "large",
]
],
"plugins" => [
'contextmenu', 'dnd', 'search', 'state', 'types', 'wholerow'
],
"contextmenu" => [
'items' =>[
'remove' => [
"label" => '删除'
]
]
],
]
]) ?>
js部分
<?php
$rename = yii\helpers\Url::to(['category/rename']);
$delete = yii\helpers\Url::to(['category/delete']);
$csrfvar = Yii::$app->request->csrfParam;
$csrfval = Yii::$app->request->getCsrfToken();
$js = <<<JS
$("#w0").on("remove.jstree", function(e, data){//删除
console.log("触发删除");
var id = data.node.id;
$.get('$delete', {id: id}, function(data){
if (data.code != 0) {
alert('删除失败:'+data.message);
window.location.reload();
}
});
})
JS;
$this->registerJs($js);
?>
但是函数触发不到,请大神指教