gpt4 book ai didi

javascript - "The property or field ' 尝试通过 JavaScript 访问 SharePoint 中库的 GUID 时 ID ' has not been initialized. It has not been requested..."

转载 作者:数据小太阳 更新时间:2023-10-29 05:26:10 26 4
gpt4 key购买 nike

我正在尝试使用 SharePoint 2013 中的客户端对象模型访问库的 ID。但出现错误:

The property or field 'Id' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

下面是我的代码:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var items = SP.ListOperation.Selection.getSelectedItems(context);
var currentLibrary = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList(context));
context.load(currentLibrary, 'id'); // Tried with 'Id' but still throws error
console.log(currentLibrary);
console.log("currentLibrary.get_id = " + currentLibrary.get_id()); // THROWS ERROR!

我在这里做错了什么?

最佳答案

错误:

The property or field 'Id' has not been initialized. It has not been requested…

因为列表对象被请求而发生。

使用SP.ClientContext.executeQueryAsync method 在服务器上异步执行当前挂起的请求

一个工作示例:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var listId = SP.ListOperation.Selection.getSelectedList(context);
var list = web.get_lists().getById(listId);
context.load(list, 'Id'); //tell SharePoint to load List Id property
context.executeQueryAsync( //submit query to the server
function(){
console.log("ID:" + list.get_id()); //process result in success callback
},
function(sender,args){
console.log(args.get_message()); //handle error in error callback
}
);

关于javascript - "The property or field ' 尝试通过 JavaScript 访问 SharePoint 中库的 GUID 时 ID ' has not been initialized. It has not been requested...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24863056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com