SP1*_*P10 4 javascript sharepoint list
我必须从图片库中读取标题和位置并使用CEWP显示.
有人可以建议如何使用Javascript读取SharePoint列表项值.
小智 14
您可以使用JavaScript客户端对象模型.假设窗口的_spPageContextInfo
对象设置与webServerRelativeUrl
,pageListId
和pageItemId
属性进行初始化:
var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
var item = list.getItemById(_spPageContextInfo.pageItemId);
Run Code Online (Sandbox Code Playgroud)
然后你可以加载你需要的字段:
context.load(item, "Title", "Location");
context.executeQueryAsync(Function.createDelegate(this, this.mySuccessFunction), Function.createDelegate(this, this.myErrorFunction));
Run Code Online (Sandbox Code Playgroud)
item
现在将填充您请求的字段,您可以像这样检索它们:
var itemTitle = item.get_item("Title");
var itemLocation = item.get_item("Location");
Run Code Online (Sandbox Code Playgroud)
请注意,您应该使用要加载的字段的显示名称而不是内部名称.