SharePoint 2010 ECMA:获取当前列表的名称

时间:2013-06-25 07:48:34

标签: javascript sharepoint sharepoint-2010

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

试图避免使用服务器端代码......

1 个答案:

答案 0 :(得分: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

此致 彼得