【Sharepoint】使用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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一起来学吧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值