【问题标题】:Why selected object is not display in console when it is clicked为什么单击时所选对象不显示在控制台中
【发布时间】:2016-01-04 21:36:19
【问题描述】:

我正在使用这个演示:https://github.com/ezraroi/ngJsTree

API 参考:https://www.jstree.com/api/#/

我做了两个例子

  1. 首先我有一个复选框。当我选择任何复选框时,它会显示选定的项目对象(codepen:http://codepen.io/naveennsit/pen/MKJdOZ?editors=101

    $scope.getSelectedCategories = function() { alert('---') var selected_nodes = $scope.treeInstance.jstree(true).get_checked(true); console.log(selected_nodes); };

  2. 但是当我删除这个复选框时,点击和选择的项目不会显示在控制台中(codepen:http://codepen.io/naveennsit/pen/RrKmxp

我在两个示例中都使用了相同的功能,但第二个不起作用。

【问题讨论】:

  • 您有多个指向不同外部资源的链接来演示您的代码。将相关内容移到帖子中 - 如果人们不必打开多个浏览器窗口来找出您拥有的代码,他们将更有可能提供帮助。

标签: angularjs angularjs-directive angularjs-scope angular-ui-router jstree


【解决方案1】:

根据 jsTree 的文档 .get_checked(true) 返回“所有已检查节点的数组”。如果您没有与节点关联的复选框,那么我不确定它是否会起作用。否则,如果没有重要的解决方法,它将无法工作。但是,文档说“如果在设置中启用了 tie_selection,则此函数将返回与 get_selected 相同的值”。这可能会为您提供您寻求的解决方案。否则,您可以将 .get_checked 更改为 .get_selected 我使用的文档可以找到here. .get_checked 仅供参考。

编辑 我决定自己试试。

$scope.getSelectedCategories = function() {
    var selected_nodes = $scope.treeInstance.jstree(true).get_selected(true);
    alert(JSON.stringify(selected_nodes));
};

这提醒了对象。

【讨论】:

    猜你喜欢
    • 2012-04-16
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 2016-01-19
    • 1970-01-01
    • 2020-11-06
    相关资源
    最近更新 更多