我是第一次使用 dynatree 插件,我正在尝试动态添加节点。 我的代码如下:
function DrawTree() {
var names = GetChildName();
var rootNode = $("#ProcessRoleTree").dynatree("getRoot");
var childNode = rootNode.addChild({ title: names[0].Name });
}
运行时显示错误
Microsoft JScript runtime error: Object doesn't support this property or method
我错过了什么吗? 我已经确认我包含了所需的库:
<script src="Jquery/jquery/jquery.js" type="text/javascript"></script>
<script src="Jquery/jquery/jquery-ui.custom.js" type="text/javascript"></script>
<script src="Jquery/jquery/jquery.cookie.js" type="text/javascript"></script>
<link href="Jquery/src/skin-vista/ui.dynatree.css" rel="stylesheet" type="text/css" />
<script src="Jquery/src/jquery.dynatree.js" type="text/javascript"></script>
提前致谢!
最佳答案
这可能不是您的问题,但值得一试。有时,当将 jQuery 与其他库一起使用时,您可能会遇到代码冲突的情况。 jQuery 使用 $ 符号作为 jQuery 的快捷方式。 dynatree 库也使用美元符号来表示其功能。
我在实现我的树时遇到了这个问题,这就是我修复它的方法。如您所见,我将所有“$”替换为“jQuery”。
<script type="text/javascript">
jQuery.noConflict();
function DrawTree() {
var names = GetChildName();
jQuery("#ProcessRoleTree").dynatree();
var rootNode = jQuery("#ProcessRoleTree").dynatree("getRoot");
//Try adding a key
var childNode = rootNode.addChild({ title: names[0].Name, key: "001" });
}
</script>
关于javascript - 无法使用addChild方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9664787/