我正在使用 jstree 和 contextmenu 插件使用 Laravel 创建文件夹树,前端一切正常,但我不知道如何将 JavaScript 函数连接到 Laravel Controller 函数,以便我可以创建、重命名和删除节点并将其保存到MySQL数据库
我已经准备好带有 console.log 消息的 JavaScript 函数
<script>
$(function() {
$('#container').jstree({
"core" : {
"check_callback" : true,
"themes" : { "stripes" : true },
},
"plugins" : ['crrm','dnd','search','contextmenu'],
}).on('rename_node.jstree', function(e, data) {
console.log('rename');
}).on('delete_node.jstree', function(e, data) {
console.log('deleted');
}).on('create_node.jstree', function(e, data) {
console.log('create');
});
});
</script>
感谢您的宝贵时间!
最佳答案
您可以使用ajax连接到 Controller 。
将其添加到您的三个 .on 语句中
function(e, data) {
$.ajax({
url: '/controllerMethod',
method: 'post',
data: data,
success:function(data){
console.log(data);
}
}
关于javascript - jstree 使用 contextmenu 插件和 laravel 创建编辑重命名功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54666782/