其他分享
首页 > 其他分享> > 转:使用SharePoint rest api对list中的数据进行获取、排序、筛选、分页操作

转:使用SharePoint rest api对list中的数据进行获取、排序、筛选、分页操作

作者:互联网

获取数据

1、获取所有数据(所有字段)

https://weburl/_api/web/lists/getbytitle('infolist')/items

2、获取指定字段

可以通过select来指定需要获取的字段:$select=Field1, Field2, Field3 

 https://weburl/_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company

排序操作

可以通过orderby来指定某列进行排序操作:$orderby=(列内部名称 order)

升序:   https://weburl/_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company&$orderby= Employee asc

降序:   https://weburl/_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company&$orderby= Employee desc

筛选操作

 可以通过filter指定某列作为条件进行数据的筛选操作:$filter=(列内部名称 operator value)

列类型为文本   /_api/web/lists/getbytitle('infolist')/items?$filter= Employee eq ‘parth'
列类型为数值 /_api/web/lists/getbytitle('infolist')/items?$filter=ID eq 2
列类型为日期  /_api/web/lists/getbytitle('infolist')/items?$filter=Start_x0020_Date le datetime'2020-10-01T09:59:32Z'
多条件筛选 /_api/web/lists/getbytitle('infolist')/items?$filter=( Modified le datetime'2016-03-26T09:59:32Z') and (ID eq 2)
以某个字符串开头的数据 /_api/web/lists/getbytitle(‘'infolist')/items?$filter=startswith(Title,‘P’)
通过日期函数获取某月数据 /_api/web/lists/getbytitle(‘'infolist')/items? $filter=month(Modified) eq 5

筛选操作运算符

支持的运算符

不支持的运算符

数值比较

  • Lt
  • Le
  • Gt
  • Ge
  • Eq
  • Ne
  • 算术操作符不支持 

    (Add, Sub, Mul, Div, Mod)

  • 基本的数学函数不支持 

    (round, floor, ceiling)

字符串比较

  • startsWith
  • substringof
  • Eq
  • Ne
  • endsWith
  • replace
  • substring
  • tolower
  • toupper
  • trim
  • concat

日期和时间函数

  • day()
  • month()
  • year()
  • hour()
  • minute()
  • second()
 

 分页操作(获取前几条数据)

可以通过 $top number,获取前number条数据

https://weburl/_api/web/lists/getbytitle('infolist')/items?$top 5

获取person或lookup字段

可以通过$expand获取person或lookup字段

1、Lookup 字段: 比如在一个list中,字段city为lookup字段,那么可以通过expand获取city对应的id 

https://weburl/_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company,city/Id&$expand= city/Id

2、People 字段: 比如在一个list中,获取创建者用户id

 https://weburl/_api/web/lists/getbytitle('infolist')/items?$select=Author/Title&$expand=Author/Id

标签:web,infolist,items,SharePoint,list,getbytitle,rest,api,lists
来源: https://www.cnblogs.com/hanrend/p/14390069.html