jstree create_node with li_attr

huangapple go评论53阅读模式
英文:

jstree create_node with li_attr

问题

You can use the "li_attr" data attribute while using the create_node function as follows:

.jstree('create_node', $(parent_node), eval(new_node_text), position, false, false, { "li_attr": { "your_attribute_name": "your_attribute_value" } });
英文:

i am using jstree and am already adding new nodes with the create_node function. But can anyone tell me how to add "li_attr" data while using the create_node function?

Thanks in advance

.jstree('create_node', $(parent_node), eval(new_node_text), position, false, false);

答案1

得分: 0

希望这对你有所帮助。你可以修改li_attr属性以包含你在使用情况中需要的任何其他属性或值。

// 定义新节点的文本和其属性
var new_node_text = {
  "text": "新节点",
  "li_attr": {
    "data-attribute1": "value1",
    "data-attribute2": "value2"
  }
};

// 创建新节点并将其添加到父节点
$("#jstree").jstree("create_node", parent_node, new_node_text, "last", function(node) {
  // 节点创建后调用的回调函数
  // 在这里,你可以对新节点执行任何其他操作
});
英文:

Hope This helps you. You can modify the li_attr property to include any other attributes or values that you need for your use case.

// Define the new node text and its attributes
var new_node_text = {
  "text": "New Node",
  "li_attr": {
    "data-attribute1": "value1",
    "data-attribute2": "value2"
  }
};

// Create the new node and add it to the parent node
$("#jstree").jstree("create_node", parent_node, new_node_text, "last", function(node) {
  // Callback function called after the node has been created
  // Here you can perform any additional actions on the new node
});

huangapple
  • 本文由 发表于 2023年5月7日 15:42:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定