Pro SharePoint with JQuery笔记1
来源:互联网 发布:php开发qq客户端 编辑:程序博客网 时间:2024/04/28 11:34
加载JQuery:
将JS文件加载到SharePoint环境中的方法
SharePoint Client Object Model基础:
1. 使用Client Object Model之前需要加载sp.js文件,加载方法:
SharePoint 2010:
$(document).ready(function(){ ExecuteOrDelayUntilScriptLoaded(MyFunction, "sp.js");});function MyFunction(){ ... }
SharePoint 2013:
$(document).ready(function(){ SP.SOD.executeFunc("sp.js", "SP.ClientContext", MyFunction);});function MyFunction(){ ... }
2. 使用ClientContext对象获取当前SharePoint信息:
获取当前ClientContext对象:
var context = new SP.ClientContext.get_current();获取当前web对象:
var web = context.get_web();context.load(web);context.executeQueryAsync(SucceedFunction, FailedFunction); //执行异步查询获取web的信息,SucceedFunction和FailedFunction是回调函数。获取title为“abc”的列表:
var web = context.get_web();var list = web.get_lists().getByTitle("abc");context.load(list);context.executeQueryAsync(SucceedFunction, FailedFunction); //执行异步查询获取list的信息获取id为1的item:
var item = list.getItemById("1");获取所有的item:
var web = context.get_web();var list = web.get_lists().getByTitle("abc");var allItems = list.getItems("");context.load(allItems, 'include(ID, Title)'); //使用include指定获取的field信息context.executeQueryAsync(SucceedFunction, FailedFunction); //执行异步查询获取所有的item遍历所有item:
var itemCollection = allItems.getEnumerator();while(itemCollection.moveNext()){ var myItem = itemCollection.get_current(); ... ...}获取item的field值:
var title = myItem.get_item('Title'); //参数是field的internal name更新item的field值:
myItem.set_item('Title', 'new title');myItem.update();删除一个item:
myItem.deleteObject();context.executeQueryAsync(SucceedFunction, FailedFunction);处理异步查询的异常:
function FailedFunction(sender, args){ //使用args参数获得具体的错误信息 alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());}向list中添加一条item:
var context = new SP.ClientContext.get_current(); var web = context.get_web(); var list = web.get_lists().getByTitle("abc"); var listItemInfo = new SP.ListItemCreationInformation(); //创建一个ListItemCreationInformation对象 var listItem = list.addItem(listItemInfo); //添加item listItem.set_item('Title', 'new item'); //设置item的title listItem.update(); context.executeQueryAsync(SucceedFunction, FailedFunction); //执行异步查询,在list中创建item
使用ajax调用web service,获取“Task”列表中的items,并且遍历显示Title字段:
function LoadItems() { var taskUrl = "/_vti_bin/ListData.svc/Task/"; //如果Task列表位于子站点sub中,这里需要使用/sub/_vti_bin/ListData.svc/Task/ $.ajax({ type: 'GET', url: taskUrl, dataType: 'json', success: function(data) { //成功的返回值是data对象,其中的d的results属性包含item $.each(data.d.results, function(i, result) { alert('Title: '+result.Title); }); }); }, error: function() { alert("error"); } });}
使用ajax的getJSON方法获取一条item的数据:
function LoadItem(id) { var itemUrl = "/_vti_bin/ListData.svc/Task(" + id + ")"; $.getJSON(itemUrl, function(data) { alert($(data.d.Title)); });}
0 0
- Pro SharePoint with JQuery笔记1
- 《Pro Android C++ with the NDK》 第三章阅读笔记
- Pro SharePoint 2003 Development Techniques
- Pro SharePoint 2003 Development Techniques
- Pro SharePoint 2007 Development Techniques
- pro git学习笔记(1)
- SharePoint Designer Tutorial: Working with SharePoint Websites
- Customizng SharePoint Content with SharePoint Designer 2007
- Personalize a SharePoint Site with Audiences - Part 1
- Pro SharePoint Solution Development: Combining .NET, SharePoint and Office 2007
- 读书笔记<Pro SharePoint 2013>一[增强]
- 读书笔记<Pro SharePoint 2013>二[服务]
- 读书笔记<Pro SharePoint 2013>三[Tip]
- Pro JavaScript Techniques 学习笔记1
- 《Pro Git 2》学习笔记_Chapter 1
- sharepoint&wcf&jquery
- Pro Apache Struts with Ajax
- The First Pro with wxpython
- Hadoop本地库与系统版本不一致引起的错误解决方法
- 如何让Div中的Table居中
- VC实现打开BMP
- android蓝牙传输文件时的文件格式限制及其解决方法
- java字符编码转换研究(转)
- Pro SharePoint with JQuery笔记1
- Evaluate Reverse Polish Notation
- c++按位操作符
- IOS开发Scoket接受报文不全(分多次接受)的TCP粘包问题
- android SearchView 样式修改
- ios设备唯一标识获取策略
- 一步步学习SPD2010--第十一章节--处理母版页(3)--母版页上使用的控件
- 如何让静态局部和全局变量或数组存在指定地址的Flash
- 黑马程序员___ 基础加强篇(二)