简体   繁体   English

SharePoint 2013在allitems.aspx中我如何获取列表标题和名称

[英]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. 在Alert Me中,当我的JavaScript代码位于文档库的allitems.aspx页面中时,我试图获取当前列表的名称和标题。 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 ) 至少以下选项可用于确定“列表视图”页面( AllItems.aspx )中的列表属性(如Title

Using SP.ListOperation.Selection namespace 使用SP.ListOperation.Selection命名空间

SP.ListOperation.Selection.getSelectedList() Method gets the ID of the list being selected: SP.ListOperation.Selection.getSelectedList()方法获取所选列表的ID:

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

The following example demonstrates how to retrieve list by its Id via CSOM (JavaScript): 以下示例演示如何通过CSOM(JavaScript)通过其ID检索列表:

(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结构

_spPageContextInfo object is rendered in every SharePoint page and contains property _spPageContextInfo.pageListId that stores the current List Id: _spPageContextInfo对象在每个SharePoint页面中呈现,并包含存储当前列表ID的_spPageContextInfo.pageListId属性:

var listId = _spPageContextInfo.pageListId;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在Sharepoint allitems.aspx页面中将静态值调整为动态(javascript)值? - Adjust static value into dynamic (javascript) value possible in Sharepoint allitems.aspx page? 如何在SharePoint 2013中编码REST的列表名称 - How to encode a list name for REST in sharepoint 2013 如何通过Sharepoint 2013中的标题获取网站的URL? - How to get a site's URL by its title in Sharepoint 2013? 使用JavaScript修改SharePoint 2013列表列标题 - SharePoint 2013 list column title modification with javascript 获取数组javascript Sharepoint中最长的列表标题名称 - Get longest List title name in array javascript Sharepoint 如何通过在SharePoint2013中使用angularJS登录的用户筛选列表结果 - How do I filter my list results by the user logged on using angularJS in SharePoint2013 Sharepoint2013 REST:如何处理GetByTitle('')列表标题中有问题的字符? - Sharepoint2013 REST: How to handle problematic characters in GetByTitle('') list title? 如何使用按钮激活 SharePoint 2013 工作流程(javascript?) - How do I activate a SharePoint 2013 workflow with a button (javascript?) 如何在SharePoint 2013 JSOM中设置URL字段的值 - How do I set the value of a URL field in the SharePoint 2013 JSOM 如何在sharepoint 2013中获取oauth访问令牌? - How can I get an oauth access token in sharepoint 2013?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM