5

On my publishing site I have changed its current navigation (quick launch) to use structural navigation, showing all items under current site. I see that the quick launch shows pages and sub sites for current site. However when I use my JSOM to retrieve all nodes in the quick launch it does not return any node at all and it seems it is empty, the rest api does not return any item either (_api/web/navigation/QuickLaunch) following is my code.

var clientContext = new SP.ClientContext.get_current();
var currentQL = clientContext.get_web().get_navigation().get_quickLaunch();
clientContext.load(currentQL);
clientContext.executeQueryAsync(Function.createDelegate(this, function (sender, args) {
   var qlEnum = currentQL.getEnumerator();
   var temp = "";

   while (qlEnum.moveNext()) {
      var node = qlEnum.get_current();
      var title = node.get_title();
      var url = node.get_url();
      temp += title + ":" + url + "\r";
   }
   alert(temp);    
}),
Function.createDelegate(this, function (sender, args) {
    alert(args.get_message());
}));

2 Answers 2

2

The "get_QuickLaunch()" method will return the collection of nodes that have been added to the Quick Launch collection. However, changing what is rendered in the UI does not actually change that collection of nodes.

The CSOM contains only a minimal set of APIs for the publishing model, so you will need to read the items in the Pages library using the List API and subsites using SP.Web.getSubWebsForCurrentUser(). Use caution on that however, since enumerating subsites for a user is somewhat intensive and being executed on every page could impact performance.

1
  • Are you saying that you can't permanently add/remove/change nodes in the Quick Launch using the CSOM? Dec 4, 2015 at 18:11
1

A little delayed, but it could help someone one day. Be aware that there is a difference between the Top Navigation and the Quick Launch. Based on what you've written Medes, you appear to think that the Quick Launch contain your site link and his subsites links, but what's doing this is the Top Navigation. the Quick launch menu is designed to contain the needed pages or webpart within you current site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.