简体   繁体   中英

SharePoint 2013 In allitems.aspx How Do I get the list title and Name

I am trying to mimic the Alert Me functionality as the business only wants Alert Me and Send a link. In Alert Me I am trying to get the current list's Name and Title when my javascript code is in the allitems.aspx page of my document library. All of the examples I can find assume you know the title of the list already.

At least the following options could be used to determine list properties (like Title ) in List View page ( AllItems.aspx )

Using SP.ListOperation.Selection namespace

SP.ListOperation.Selection.getSelectedList() Method gets the ID of the list being selected:

var listId = SP.ListOperation.Selection.getSelectedList(); 

The following example demonstrates how to retrieve list by its Id via CSOM (JavaScript):

(function(){

  var listId = SP.ListOperation.Selection.getSelectedList(); //selected List Id
  var context = new SP.ClientContext.get_current();
  var web = context.get_web();
  var list = web.get_lists().getById(listId);

  context.load(list);
  context.executeQueryAsync(
     function() {
       //print List properties
       console.log(list.get_title());
     },
     function(sender,args){
        console.log(args.get_message());
     }
  );
})();

Using _spPageContextInfo structure

_spPageContextInfo object is rendered in every SharePoint page and contains property _spPageContextInfo.pageListId that stores the current List Id:

var listId = _spPageContextInfo.pageListId;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM