The sample is not a solution, it is test code
Ok I understood !!!!
well, the Id is a GUID and GUIDs always contains a "-"
I added the columns to add an identifier.
It loops over the same FilePathPs collection twice. On the second loop the logic concatenates OrgLevel with Id separated by an "-".
Do you have a proposal?
I reproduced my same issue with your structure.
In this case I returned any selectedItem. So I think there a problem with js script.
[BindProperty]
public List<TreeViewNode>? Nodes { get; set; }
public void OnGet()
{
Nodes = new List<TreeViewNode>()
{
new TreeViewNode()
{
id = "1",
parent = "",
text = "Root"
},
new TreeViewNode()
{
id = "2",
parent = "Root",
text = "Folder1"
},
};
}
public void OnPost(string selectedItems)
{
Nodes = System.Text.Json.JsonSerializer.Deserialize<List<TreeViewNode>>(selectedItems);
}
Js Script
<script type="text/javascript">
$(function () {
$('#jstree').on('changed.jstree', function(e, data) {
var i, j;
var selectedItems = [];
for (i = 0, j = data.selected.length; i < j; i++) {
//Fetch the Id.
var id = data.selected[i];
//Remove the ParentId.
if (id.indexOf('-') != -1) {
id = id.split("-")[1];
}
//Add the Node to the JSON Array.
selectedItems.push({
text: data.instance.get_node(data.selected[i]).text,
id: id,
parent: data.node.parents[0]
});
}
}).jstree({
"core": {
"themes": {
"variant": "large"
},
"data": {
var json = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.Nodes));
document.getElementById("selectedItems").value = JSON.stringify(json);
console.log(json);
}
},
"checkbox": {
"keep_selected_style": false
},
"plugins": ["wholerow", "checkbox"],
});
});
</script>