在加载时获取 javascript 中当前选定的列表 - sharepoint 2010
我目前正在尝试找出如何从 javascript 获取对 sharepoint 中当前选定列表的引用。如果我知道标题或 ID,我就可以获取它,但我希望它根据用户所在位置动态获取列表。我有以下代码(在我的模式对话框中):
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());
}
问题是 SP.ListOperation.Selection.getSelectedList()
返回 null。可能还有一些其他脚本我需要等待 - 但哪一个呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了。
SP.ListOperation.Selection.getSelectedList()
在模式对话框内不起作用。我需要从父窗口传递列表 ID。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.您可能在 SharePoint Web 服务中发现了一个错误(考虑到 API 的稀疏性,这并不特别令人惊讶)。
请参阅此处。我没有仔细看,但 BananaRepublic 似乎有一个解决这个问题的方法;我不知道确切的上下文,所以我不知道它是否适合你。
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.