【问题标题】:SharePoint 2010 ECMA : get name of current listSharePoint 2010 ECMA:获取当前列表的名称
【发布时间】:2015-01-26 09:47:58
【问题描述】:

在内容编辑器 Web 部件中,如何通过 ECMA 获取当前列表名称? 内容编辑器 Web 部件位于列表的 AllItems 视图中。

尽量避免服务器端代码...

【问题讨论】:

    标签: javascript sharepoint sharepoint-2010


    【解决方案1】:

    COM、ECMA 和服务器端对象模型不提供我看到的这个功能,但如果有人能提供更好的解决方案,那就太好了。我用来获取ListName的脚本如下,

    function getListTitle() {
    
    clientContext = new SP.ClientContext.get_current()
    oWeb = clientContext.get_web();
    oListColl = oWeb.get_lists();
    oList = oListColl.getById(SP.ListOperation.Selection.getSelectedList());
    clientContext.load(oList);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
    
    function onQuerySucceeded() {
    
    var s = window.location.toString().substring(0, window.location.toString().lastIndexOf('/'));
    if (s.endsWith('Forms')) {
        s = s.substring(0, s.length - 6);
    }
    }
    
    function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    

    我假设列表的意思是列表的 URL 作为名称很容易,oList.get_title

    问候 彼得

    【讨论】:

    • 不要使用这个解决方案,它完全是假的。那么在客户端上下文上执行查询,然后完成 url 解析?为什么?您无需执行查询即可。
    • @Luis 那么你的答案在哪里?
    猜你喜欢
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 2012-06-21
    • 2011-05-03
    • 2017-03-25
    • 1970-01-01
    • 2017-06-02
    相关资源
    最近更新 更多