获取所有的List Items
function getItems(url) {
$.ajax({
url: url,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function(data) {
//console.log(data);
for(var i=0;i<data.d.results.length;i++){
  console.log(data.d.results[i].Number);
  }
if (data.d.__next) {
getItems(data.d.__next);
}
},
error: function(jqxhr) {
alert(jqxhr.responseText);
}
});
}
getItems(_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Association')/items");

 删除所有的List Items: (获取所有的list Items可以使用上面的方法)

function deleteItem(url,prm) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "DELETE",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": "*"
},
success: function (data) {
console.log(prm);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
} $.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Association')/items?$filter=Number%20ne%20%27120%27&$top=2000",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
var items = data.d.results;
console.log(items.length);
for(var i=0;i<items.length;i++){
var url = "/_api/Web/Lists/getByTitle('Association')/getItemById("+items[i].ID+")";
deleteItem(url,items[i].ID);
}
},
error: function (error) {
alert(JSON.stringify(error));
}
}); 删除单个:
function deleteListItem() {
var id = $("#txtId").val();
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var fullUrl = siteUrl + "/_api/web/lists/GetByTitle('MyCompanyInfo')/items(" + id + ")";
$.ajax({
url: fullUrl,
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "DELETE",
"IF-MATCH": "*"
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
function onQuerySucceeded(sender, args) {
$("#divResult").html("Item successfully deleted!");
}
function onQueryFailed() {
alert('Error!');
}

  

 添加List Items:

function addListItem() {
var title = $("#txtTitle").val();
var industry = $("#txtIndustry").val();
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var fullUrl = siteUrl + "/_api/web/lists/GetByTitle('MyAssociation')/items";
var itemType = GetItemTypeForListName(listName);
$.ajax({
url: fullUrl,
type: "POST",
data: JSON.stringify({
'__metadata': { 'type': itemType },//'SP.Data.MyAssociationListItem'
'Title': title,
'Industry': industry
}),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
function onQuerySucceeded(sender, args) {
$("#divResult").html("Item successfully added!");
}
function onQueryFailed() {
alert('Error!');
} // Get List Item Type metadata
function GetItemTypeForListName(name) {
return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}

Update List Items:

ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
function initializePage() {
var siteURL;
var itemsArray = [];
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function() {
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
UpdateListItem();
});
}
//Retrieve list items from sharepoint using API
function UpdateListItem() {
siteURL = _spPageContextInfo.webAbsoluteUrl;
console.log("from top nav - " + siteURL);
var apiPath = siteURL + "/_api/lists/getbytitle(''samplelist'')/items/getbyid(1)";
$.ajax({
url: apiPath,
type: "POST",
headers: {
Accept: "application/json;odata=verbose"
},
data: "{__metadata:{'type':'SP.Data.YourlistnameListItem'},Title:”Ur input "
}
",
async: false, success: function(data) {
alert("Item updated successfully");
}, eror: function(data) {
console.log("An error occurred. Please try again.");
}
});
}

How to update List Item via SharePoint REST interface:

function updateJson(endpointUri,payload, success, error)
{
$.ajax({
url: endpointUri,
type: "POST",
data: JSON.stringify(payload),
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest" : $("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"If-Match": "*"
},
success: success,
error: error
});
} function getItemTypeForListName(name) {
return"SP.Data." + name.charAt(0).toUpperCase() + name.slice(1) + "ListItem";
} function updateListItem(webUrl,listTitle,listItemId,itemProperties,success,failure)
{
var listItemUri = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items(" + listItemId + ")";
var itemPayload = {
'__metadata': {'type': getItemTypeForListName(listTitle)}
};
for(var prop in itemProperties){
itemPayload[prop] = itemProperties[prop];
}
updateJson(listItemUri,itemPayload,success,failure);
} Usage: var itemProperties = {'Title':'John Doe'};
updateListItem(_spPageContextInfo.webAbsoluteUrl,'Contacts',1,itemProperties,printInfo,logError);
function printInfo()
{
console.log('Item has been created');
}
function logError(error){
console.log(JSON.stringify(error));
}

 https://blogs.msdn.microsoft.com/uksharepoint/2013/02/22/manipulating-list-items-in-sharepoint-hosted-apps-using-the-rest-api/ 

 

获取所有的List Items Count:

_spPageContextInfo.webAbsoluteUrl+" _api/web/lists/getByTitle('DepartProd')/itemcount"   //?$filter=AssignedTo/ID eq 2

Rest API 操作List Items的更多相关文章

  1. Python API 操作Hadoop hdfs详解

    1:安装 由于是windows环境(linux其实也一样),只要有pip或者setup_install安装起来都是很方便的 >pip install hdfs 2:Client——创建集群连接 ...

  2. 转 用C API 操作MySQL数据库

    用C API 操作MySQL数据库 参考MYSQL的帮助文档整理 这里归纳了C API可使用的函数,并在下一节详细介绍了它们.请参见25.2.3节,“C API函数描述”. 函数 描述 mysql_a ...

  3. hive-通过Java API操作

    通过Java API操作hive,算是测试hive第三种对外接口 测试hive 服务启动 package org.admln.hive; import java.sql.SQLException; i ...

  4. Hadoop学习记录(3)|HDFS API 操作|RPC调用

    HDFS的API操作 URL方式访问 package hdfs; import java.io.IOException; import java.io.InputStream; import java ...

  5. HBase 6、用Phoenix Java api操作HBase

    开发环境准备:eclipse3.5.jdk1.7.window8.hadoop2.2.0.hbase0.98.0.2.phoenix4.3.0 1.从集群拷贝以下文件:core-site.xml.hb ...

  6. hadoop2-HBase的Java API操作

    Hbase提供了丰富的Java API,以及线程池操作,下面我用线程池来展示一下使用Java API操作Hbase. 项目结构如下: 我使用的Hbase的版本是 hbase-0.98.9-hadoop ...

  7. 使用Java API操作HDFS文件系统

    使用Junit封装HFDS import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import org ...

  8. HBase API操作

    |的ascII最大ctrl+shift+t查找类  ctrl+p显示提示 HBase API操作 依赖的jar包 <dependencies> <dependency> < ...

  9. MSComm控件与Win32 API操作串口有何区别?

    MSComm控件与Win32 API操作串口有何区别? [问题点数:50分,结帖人shell_shell]   收藏帖子 回复 我是一个小兵,在战场上拼命!   结帖率 83.33% 我以前用MSCo ...

随机推荐

  1. subset_lat_dir.sh

    #!/bin/bash     # Copyright 2018 Jarvan Wang # Copyright 2017 Vimal Manohar # Apache 2.0.     cmd=ru ...

  2. redhat7.4切换yum源为免费源

    1.redhat是Linux系统中付费的企业版,虽然安装什么是免费的,但是需要注册. 如果你有注册码,暂请出门左拐(我没有注册码,所以我也不会注册,不用往下看了). Linux系统收费版:RedHat ...

  3. ssm多数据源配置

    1.在.properties配置文件中 添加第二个数据源信息(type2,driver2, url2,username2,pawwword2) 2.修改spring-context.xml(src/m ...

  4. springboot整合springdata-jpa

    1.简介  SpringData : Spring 的一个子项目.用于简化数据库访问,支持NoSQL 和 关系数据存储.其主要目标是使数据库的访问变得方便快捷. SpringData 项目所支持 No ...

  5. java学习笔记08-switch case语句

    switch是一种选择语句,可以通过匹配某个条件,来执行某块代码 switch(expression){ case value: break;//可选 default://可选 //语句 } swit ...

  6. 03中间件mycat对pxc集群的分片处理

    安装第二个pxc集群 作为mycat的第二个分片 直接拷贝其中的一个虚拟机,然后还原到最初的状态,这样会小很多,启动改一下IP和基础配置,然后再次拷贝这个虚拟机两份改IP重启即可 正常安装pxc集群即 ...

  7. VUE项目快速构建

    IDE  :VScode 1.新建项目文件夹 ctrl+~   调出命令板,/IDE找到当前文件夹右键 点击‘在命令提示符中打开’ 安装 node:官网(https://nodejs.org/en/d ...

  8. JAVA第二次实训作业

    1.一维数组的创建和遍历. 声明并创建存放4个人考试成绩的一维数组,并使用for循环遍历数组并打印分数. 要求: 首先按“顺序”遍历,即打印顺序为:从第一个人到第四个人: 然后按“逆序”遍历,即打印顺 ...

  9. Redis实战 - 3.Hash

    hash Redis的Hash有点像一个对象(object),一个Hash里面可以存多个Key-Value对作为它的field,所以它通常可以用来表示对象. Hash里面能存放的值也能作为String ...

  10. Angular结构型指令,模块和样式

    结构型指令 *是一个语法糖,<a *ngIf="user.login">退出</a>相当于 <ng-template [ngIf]="use ...