[英]Can't retrieve metadata from a document in SharePoint inside a folder in javascript client object model
The below code is working fine for me when the document that contains the meta data isn't inside a folder. 当包含元数据的文档不在文件夹中时,下面的代码对我来说很好。 As soon as the document is placed into a folder in the document library it stops working after
while (enumerator.moveNext()) {
I've placed console.log in seperate lines in the code and that is the point at which i stop getting a response. 一旦将文档放入文档库中的文件夹中,它就会在
while (enumerator.moveNext()) {
之后停止工作while (enumerator.moveNext()) {
我已将console.log放在代码中的单独行中,这就是我不再获取的地方一个答复。
I've created a new dispform.aspx called viewitem.aspx, and this js file is linked to it to pull the metadata out and display it in different divs on the page. 我创建了一个名为viewitem.aspx的新dispform.aspx,并将此js文件链接到它以将元数据拉出并在页面上的不同div中显示它。
below is the code: 以下是代码:
function getBody() {
var context = new SP.ClientContext("https://xxx.sharepoint.com/sites/xxx");
var list = context.get_web().get_lists().getByTitle('Docs');
JSRequest.EnsureSetup();
var listItemId = GetUrlKeyValue("ID");
var item = new SP.CamlQuery();
item.set_viewXml("<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + listItemId + "</Value></Eq></Where></Query></View>");
returnedItemsBE1 = list.getItems(item);
context.load(returnedItemsBE1);
context.executeQueryAsync(onSucceededCallbackBE1);
}
function onSucceededCallbackBE1() {
var enumerator = returnedItemsBE1.getEnumerator();
while (enumerator.moveNext()) {
var listItem = enumerator.get_current();
var tmbod = listItem.get_item('TmBody');
var tmfile = listItem.get_item('TmAttachmentTitle');
var tmId = listItem.get_item('TmTransID');
var tmfileurl = 'https://xxx.sharepoint.com/sites/xxx/Docs/'+tmId+'_'+tmfile;
document.getElementById("fileLink").href = tmfileurl;
document.getElementById("fileLink").innerText = tmfile ;
var bdiv = document.getElementById("bodyDiv");
bdiv.innerHTML = tmbod;
}
}
` `
I'm using SharePoint 2013 online, I can't figure out how the item being in a folder can make any difference, the URL changes but it still contains the file ID etc... 我在线使用SharePoint 2013,我无法弄清楚文件夹中的项目如何有所不同,URL更改但它仍然包含文件ID等...
I've searched and searched and can't find any reference to this, any help would be appreciated! 我搜索和搜索,找不到任何参考,任何帮助将不胜感激!
Try using Scope='Recursive'
in you View
tag. 尝试在
View
标签中使用Scope='Recursive'
。 Else, it will only get the files in the given directory. 否则,它只会获取给定目录中的文件。
item.set_viewXml("<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + listItemId + "</Value></Eq></Where></Query></View>");
There are four view scopes: 有四个视图范围:
Default (no Scope given): retrieve all the files in the current folder 默认(未给出范围):检索当前文件夹中的所有文件
All: retrieve files and folders in the current folder 全部:检索当前文件夹中的文件和文件夹
Recursive: retrieve files in the current folder and its sub-folders, and in their sub-folders, etc. 递归:检索当前文件夹及其子文件夹及其子文件夹中的文件等。
RecursiveAll: same as Recursive, but also retrieves the sub-folders. RecursiveAll:与Recursive相同,但也检索子文件夹。
I found this handy page if a visual explanation works better for you. 如果视觉解释更适合您,我找到了这个方便的页面 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.