我已经安装了jsTree在我的 bower_components
中(使用 this post 中的指南),我的 Jade 模板看起来像这样 -
doctype html
html
head
title= title
script(src='/bower_components/jstree/dist/jstree.min.js')
script(src='/bower_components/jquery/dist/jquery.min.js')
link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='stylesheet', href='/bower_components/jstree/dist/themes/default/style.css')
script(src='/javascripts/custom/mytree.js')
body
#mytreediv
ul
li First item
li Second item
脚本mytree.js
是我编写的脚本,我在其中使用jsTree初始化mytreediv
div元素。脚本看起来像这样 -
alert('Test1');
var myfunc = function () {
alert('Test2');
$('#mytreediv').jstree();
};
myfunc();
两个 alert
框确实出现了,所以我非常确定脚本已正确链接到 HTML。但是,div 元素看起来并没有转换为 jsTree。
我在这里缺少什么?
最佳答案
你必须等待 DOM 加载,否则 jQuery 将无法找到该元素:
$(document).ready(function () {
/* your code */
})
关于javascript - 如何在 Express 中使用 jsTree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36064990/