英文:
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
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论