Sharepoint 365:获取列表中的所有项目(但表示列不存在!)

时间:2016-05-24 20:33:50

标签: javascript sharepoint sharepoint-2013

我一直在争论这个问题,并在网上到处寻找答案。我希望有人可以帮忙!

我想要做的就是在Sharepoint Online 365中查询列表并返回该列表中的所有项目及其列值。

问题在于,当我尝试列出我想要包含的列时,我知道存在的事实,我得到一个错误,说它们不存在!

我可以成功检索“标题”和项目的ID。就这样。没有自定义列。

任何人都知道为什么?!?

 <script type="text/javascript">
 
/*Below line will make sure your JavaScript method will be called only after the SP.js file loaded at the client side*/
window.onload = QueryFollowUrl;
 
function QueryFollowUrl()
{
 //Gets the Client context of the Web
 var context = new SP.ClientContext.get_current();
 
 var web = context.get_web();
 
 //Change the List Name with yours
 this.list = web.get_lists().getByTitle('Team Projects');
 var camlQuery = new SP.CamlQuery();
 
 //Reframe the Caml query as per your requirements
 var query = "<View><ViewFields><FieldRef Name='Title' /><FieldRef Name='Details' /><FieldRef Name='Status' /></ViewFields></View>";
 camlQuery.set_viewXml(query);
 listItems = this.list.getItems(camlQuery);
 context.load(list);  
 
 /*Now mention all the required filed internal name, since data from these fields only will be retrieved*/
 context.load(listItems, 'Include(Title, Details, Status)');
 //Makes asynchronous call to the Server, which will return the JSON objects
 context.executeQueryAsync(Function.createDelegate(this, this.successFollow), Function.createDelegate(this, this.failedFollow));
 return false;
}
 
//you can get the Error details if your Execution fails using get_message() method
function failedFollow(sender, args)
{
    var errorMsg = args.get_message();
    document.getElementById('projects').innerHTML = errorMsg;
}

/*Upon successful execution, Success delegate method will be called and all the requested objects will the loaded with contents*/
function successFollow(sender, args)
{
 var ListEnumerator = this.listItems.getEnumerator();
 
 while (ListEnumerator.moveNext())
 {
   var collection = ListEnumerator.get_current();
 
   /*Using get_item method you can pass the Field Internal name mentioned earlier and get the data in that respective column, if you try to use any other column other than we mentioned earlier, it will throw you error.*/
 
   var itemTitle = collection.get_item('Title');
   document.getElementById('projects').innerHTML += itemTitle+' '+itemDetails+'<br>';
 
   //your code here
 
 }
}
</script>
<h2>Current Projects (loaded using Javascript from the 'Team Projects' list)</h2>
<div id="projects"></div>

1 个答案:

答案 0 :(得分:1)

可以使用列的内部名称进行检查吗? 转到列表设置 - &gt;单击列名称。 然后在网址中,您可以找到该列的内部名称。