【问题标题】:How to get partially selected parent id in jstree如何在jstree中获取部分选择的父ID
【发布时间】:2017-05-16 15:50:17
【问题描述】:

我将“jstree”用于树视图(父子)结构 uisng 复选框并返回每个选定项目的 id。但在这里我只得到孩子的身份证,没有得到选定的父母身份证。请帮助我也得到它。

点击[enter code herehttp://jsfiddle.net/2kwkh2uL/5807/]查找代码。

【问题讨论】:

  • 请不要输入code here to,以免您的小提琴没有代码。在您的问题中包含您的代码。
  • 我检查了你的 plunker,我觉得它正在返回 id。纠正我哪里错了
  • 它只返回选定的子 ID,但我也想要父母的 ID。

标签: javascript treeview jstree


【解决方案1】:

每个对象都有一个名为parent 的键,其中包含id。答案如下:

$('#container').jstree({
    'core' : {
        'data' : [
            { "text" : "P1", "children" : [
                { "text" : "O11" },
                { "text" : "O12" },
                { "text" : "O13"}     
            ]
            },
             { "text" : "P2", "children" : [
                { "text" : "O21" },
                { "text" : "O22" },
                { "text" : "O23"}     
            ]
            },
        ]
    },
    "plugins" : ["checkbox"]
});
$('#submitdiv').show();
		$('#submit').click(function(){
			var selectedElmsIds = [];
			var selectedElms = $('#container').jstree("get_selected", true);
			$.each(selectedElms, function() {
			    selectedElmsIds.push(
          {
            id: this.id,
            parent: this.parent
          }
         );
			    console.log('Id node: '+this.id);
			    console.log('Id parent: '+this.parent);
			});
			console.log(JSON.stringify(selectedElmsIds));
		});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/jstree.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.3/themes/default/style.min.css">

<div id="container"></div>
  <div id="submitdiv" style="display:none;position:absolute">
  <button id="submit">submit</button>
</div>

Espero haberte ayudado,saludos。

PS:我很抱歉我的英语不好,我会说西班牙语并且我正在使用谷歌翻译。

【讨论】:

  • @parul 没问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多