I am creating a breadcrumb that will check the page id of the current page, and check if there's a parent, it will then get the pagename of the parent, and check again the parent if it has another parent then return again the pagename of the parent.
I have this kind of table that contains the pagename, id, and parent
here's a sample code that I have using axios
function MainCode() {
axios.get(url)
.then(function(res) {
if(!res.parent) {
html = "<div> Facebook </div>";
}
else { //with parent
//get parent
var a = GetPage(res.parent);
console.log(a); //a is undefined
//check if a has parent again and call GetPage() function
}
})
.catch(function(error) {
});
}
//re-usable function that returns the page
function GetPage(id) {
var page = "";
axios.get(url)
.then(function(res) {
page = res.pagename;
return page;
}
}
how can I achieve this?