简体   繁体   English

如何使用JavaScript从Sharepoint列表中的文件夹中获取项目?

[英]How get items from folder in Sharepoint list using JavaScript?

I have a list of Sharepoint, and with a few folders. 我有一个Sharepoint列表,还有几个文件夹。 I need to get to the contents of these folders using JavaScript, and is best to select a folder only the item that is the column AddData date is equal to the current date. 我需要使用JavaScript来获取这些文件夹的内容,并且最好仅选择一个文件夹,该列的AddData日期等于当前日期。 I would like to ask you for help. 我想请你帮忙。 The only thing I managed to get it are: 我唯一得到的是:

 context = SP.ClientContext.get_current();
 var web = context.get_web();
 list = context.get_web().get_lists().getByTitle("ExchangeRateList");
 var camlString =
    "<View><ViewFields>" +
        "<FieldRef Name='Title' />" +
        "<FieldRef Name='Modified' />" +
        "<FieldRef Name='Created' />"+
    "</ViewFields></View>";

    var camlQuery = new SP.CamlQuery();
    camlQuery.View
    camlQuery.set_viewXml(camlString);
    allAnnouncements = list.getItems(camlQuery);
    var enumerator = allAnnouncements.getEnumerator();
    while (enumerator.moveNext()) {
            var announcement = enumerator.get_current();
            var title = announcement.get_item("Title")
    ...

announcement is my folder but how get items from this folder? 公告是我的文件夹,但是如何从该文件夹中获取项目? And check AddData column? 并检查AddData列?

  • Specify CAML Today Element to render the current date in the format that is relative to the server's local time zone 指定CAML Today元素以相对于服务器本地时区的格式呈现当前日期
  • Set Scope="RecursiveAll" for View element to include items under folder(s) View element设置Scope="RecursiveAll"以在文件夹下包含项目

Query 询问

<View Scope="RecursiveAll"> 
      <Query>
          <Where>
             <Eq>
                  <FieldRef Name="AddData" />  
                  <Value Type="DateTime">   
                    <Today />   
                  </Value>   
             </Eq>
          </Where>   
     </Query>
</View>

Example

var listTitle = 'Announcements';

  var context = new SP.ClientContext.get_current();
  var web = context.get_web();
  var list = web.get_lists().getByTitle(listTitle);
  var listItems = list.getItems(createQuery());


  context.load(listItems);
  context.executeQueryAsync(
     function() {

        var c = listItems.get_count();  
        for(var i = 0; i< c;i++ ) {
          var listItem = listItems.getItemAtIndex(i);
          console.log(listItem.get_item('Title')); 
          //...
        }  
     },
     function(sender,args){
        console.log(args.get_message());
     }
  );



  function createQuery()
  {
    var qry = new SP.CamlQuery();
    qry.set_viewXml('<View Scope="RecursiveAll"> \
                        <Query>  \
                           <Where>  \
                             <Eq>   \
                               <FieldRef Name="AddData" />  \
                               <Value Type="DateTime">   \
                                 <Today />   \
                               </Value>   \
                             </Eq>  \
                           </Where>   \
                        </Query>  \
                     </View>');
    return qry;
  }

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

相关问题 如何使用 javascript 获取 Sharepoint 中列表的文件夹名称? - How to get folder names of list in Sharepoint using javascript? 使用Java脚本从Sharepoint列表的列表视图中检索项目 - Retrieve Items from a List View of a Sharepoint List using Javascript 如何使用javascript从Sharepoint列表中获取值 - how to get a value from a Sharepoint list with javascript 如何使用JavaScript在SharePoint列表中批量创建项目? - How to bulk create items in SharePoint list using javascript? 使用SPServices从另一个域上的Sharepoint获取总计列表项 - Get total list items from Sharepoint on another domain using SPServices 使用 javascript 从列表中获取项目的价值 - Get value of items from list using javascript 如何使用javascript更新所选的共享点列表项, - How to update selected sharepoint list items with javascript, 如何使用javascript获取文件夹中的文件列表 - how get list of files in a folder using javascript 如何使用JavaScript从多个网站集中获取SharePoint列表项 - How to get the SharePoint list item from multiple site collections using JavaScript SharePoint Online-Javascript将所有列表项放入选择下拉列表 - SharePoint Online - Javascript get all list items into a select drop down
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM