gpt4 book ai didi

javascript - 如何在 select_node 事件上为 jstree 添加元数据

转载 作者:行者123 更新时间:2023-11-30 06:34:46 28 4
gpt4 key购买 nike

如何在 select_node 事件上为 jstree 添加元数据。这就是我要添加的方式:

$.ajax({            
type : 'GET',
url : '/assessment/getassess',
dataType : 'json',
success : function(jsonData) {
$("#treeViewDiv").jstree({
"themes" : {
"theme" : "classic",
"dots" : true,
"icons" : true,
"url" : "/css/themes/classic/style.css"
},
"json_data" : jsonData,
"plugins" : ["themes", "json_data", "ui", "contextmenu"],
"contextmenu" : {
items : createMenu
}
}).bind("select_node.jstree", function(e, data) {
$(data.rslt.obj).data("jstree").description = "Size: 45units";
});
}
});

最佳答案

我相信您正在使用 $.data()功能不正确。

$.data() 函数的结果赋值,并让它自动保存。

你要做的是改变这一行,

$(data.rslt.obj).data("jstree").description = "Size: 45units";

对此,

// On the next line, we use "|| {}" because if the data attribute is unassigned, we want to start with a default empty object.
var jstreeData = $(data.rslt.obj).data("jstree") || {};

// assign the property(ies)/value(s) you want.
jstreeData.description = "Size: 45units";

// finally, reassign your modified object back to the data attribute.
$(data.rslt.obj).data("jstree", jstreeData);

如果数据属性由对象组成,您需要:

  1. 缓存对象;
  2. 修改缓存对象;
  3. 将修改后的缓存对象保存/分配回数据属性。

最后,要修改 data 属性,您需要使用 $.data( key, value ) 函数重载。

关于javascript - 如何在 select_node 事件上为 jstree 添加元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15292503/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com