javascript - jsTree插件中如何获取父li类

标签 javascript jquery plugins jstree

如何获取jsTree插件中的父li类?每当我尝试遍历 Javascript 树时,我都可以到达父节点,但最终得到一个对象,并且永远无法让它将父类作为字符串输出,因此我可以对其进行简单的条件检查。

这就是我想做的:

  // JS Tree Event handler for when a node is clicked
  $("#dutchData").bind("select_node.jstree", function (e, data) {
    // get the parent node class, and then use it in a conditional statement
    var parentNodeClass = data.node.parent.attr('class'); // this is wrong, just to demonstrate
    if(parentNodeClass != 'x'){
      // do something
    }
  });

最佳答案

这是因为 parent 属性不是元素,而是元素的字符串 id。您可以使用 jQuery 获取父级,然后获取类,如下所示:

$('#'+data.node.parent).attr('class');

检查 fiddle :Fiddle

关于javascript - jsTree插件中如何获取父li类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34521544/

相关文章:

javascript - 如何让步进电机随时间转动360度?

javascript - 在 AngularJS 服务中加载模块

php - 当来自 php 的参数时,javascript 函数不会被调用

jquery - 如何使用 jQuery Mobile 防止链接添加到历史堆栈

php - WooCommerce 结帐 - 如何为特定地址提供免费送货服务

python - 是否有处理 "...more"的 Django 模板过滤器,当您单击它时,它会显示更多文本?

asp.net - 在 asp.net 中回发完成时如何滚动到页面底部?

javascript - 我们可以在 jquery 的 .each 中使用 .each 吗?

jquery - 正好 10 位数字的电话号码验证

jQuery 插件pluginname();不是一个函数