0

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 enter image description here

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?

Aventus
  • 153
  • 8
  • Check for a recursive function. What is not working with your current code ? – Weedoze Jul 22 '19 at 06:50
  • when I check the value of `var a` it is undefined. I need the value from GetPage so I can get the pageid and parentid – Aventus Jul 22 '19 at 23:23

0 Answers0