List question 2

image
List question2
.tap(() => {
const currentID = list.accordionIndex;
const currentText = list.value;
const parentID = list.tree.getParent(currentID);
let parentText;
if (parentID) parentText = list.tree.getData(parentID).obj;
zog(currentID, currentText, parentID, parentText);
});
this code mean? list.tree mean?

An accordion-type List uses a ZIM Hierarchy to keep track of data. This is a tree, with branches. So we call the property tree. The Hierarchy is in the Docs at https://zimjs.com/docs.html?item=Hierarchy and has some methods that help.

but in console ,parentID and parentText all is undefined,why?
image

Looks like we lost the method at some point. Tested back a few versions and no luck yet. Will have a look and let you know.

It was a typo in the List example in the Docs. The Hierarchy docs say that it is the id in the format: id2, etc. with the string id in front. The id is actually a property in an object literal and cannot just be a number.

const currentID = list.accordionIndex;
const currentText = list.value;
const parentID = list.tree.getParent("id"+currentID);
let parentText;
if (parentID) parentText = list.tree.getData(parentID).obj;
zog(currentID, currentText, parentID, parentText);

ok, :white_check_mark: