最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

get currently selected list in javascript on load - sharepoint 2010 - Stack Overflow

programmeradmin2浏览0评论

I'm currently trying to find out, how to get a reference to currently selected list in sharepoint from javascript. I can get it if I know the title, or id, but I want it to get the list dynamically depending on where the user is. I have this code (in my modal dialog):

ExecuteOrDelayUntilScriptLoaded(init, 'sp.js');

function init() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
}

The problem is that SP.ListOperation.Selection.getSelectedList() returns null. There is probably some other script I need to wait for - but which one?

I'm currently trying to find out, how to get a reference to currently selected list in sharepoint from javascript. I can get it if I know the title, or id, but I want it to get the list dynamically depending on where the user is. I have this code (in my modal dialog):

ExecuteOrDelayUntilScriptLoaded(init, 'sp.js');

function init() {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
}

The problem is that SP.ListOperation.Selection.getSelectedList() returns null. There is probably some other script I need to wait for - but which one?

Share Improve this question edited Jun 21, 2011 at 19:15 Mark Mascolino 2,2921 gold badge15 silver badges21 bronze badges asked Jun 21, 2011 at 9:14 NecrosNecros 3,03425 silver badges29 bronze badges 1
  • Related Q&A on SharePoint.SE about the current list item, maybe it will help: sharepoint.stackexchange./questions/11169/… – Kit Menke Commented Jun 21, 2011 at 14:12
Add a ment  | 

2 Answers 2

Reset to default 3

I figured it out. SP.ListOperation.Selection.getSelectedList() doesn't work inside of a modal dialog. I needed to pass list ID from the parent window.

You may have found a bug in SharePoint web services (not that that's particularly surprising, given the sparseness of their API).

See here. I didn't look too carefully but BananaRepublic seemed to have a workaround for this problem; I don't know the exact context, so I don't know if it will work for you or not.

发布评论

评论列表(0)

  1. 暂无评论