繁体   English   中英

如何使用 jquery 通过 SharePoint 中的 ID 检索文档库

[英]How to retrieve a Document Library by it's ID in SharePoint using jquery

我在 CommandUI.Ribbon 上有一个自定义操作。 它触发 SharePoint 加载项并将 ListID 作为参数发送。

在加载项页面中,我尝试上传文档(来自休息服务)。

当我尝试通过它的 ID 获取文档库时,它会退出调试器,我不知道为什么。

var ctx = SP.ClientContext.get_current();
var fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url(documentName);
fileCreateInfo.set_overwrite(true);
fileCreateInfo.set_content(content);

var parentList = ctx.get_web().get_lists().getById(listId);  //steps out here. 

getById 方法是否可能不存在?

希望听到你们的消息...

如果您计划使用 JSOM 从 SharePoint 查询列表,您还应该执行 executeQuery。 使用JSOM的流程是:

  1. 获取上下文
  2. 将您需要的内容加载到上下文中
  3. 执行查询以初始化对象
  4. 在查询成功时获取您需要的数据。

请参阅此msdn 文章以获取更多信息

我想根据您的需要,这种解决方案可能会奏效



    function retrieveAllListProperties() {

        var clientContext = SP.ClientContext.get_current();
        var oWebsite = clientContext.get_web();
        this.collList = oWebsite.get_lists().getById('[PLACE LIST GUID HERE]');

        clientContext.load(collList);

        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }

    function onQuerySucceeded() {
        console.log(collList.get_title());
    }

    function onQueryFailed(sender, args) {
        console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

如果您有正确的上下文,并且列表存在并且所需的权限,则运行retrieveAllListProperties() 的输出应该是查询列表的标题。

我希望这会有所帮助:)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM