Content Editor Webpart(三)使用JSOM
2015-03-20 10:21
232 查看
JSOM是SharePoint 提供的一种客户端API。开发人员只需要使用Javescript,就可以实现和SharePoint的交互,非常方便。
首先按照 (Content Editor Webpart(一)引用JQuery) 中的说明,引入JQuery。然后在Content Editor中添加代码。
比如要获取site的title 和description。
和Server OM不同的是,客户端OM,必须要先调用Load方法,再调用execute方法,才去与服务器交互。executeQueryAsync方法,定义了两个事件,一个是处理成功的情况,一个处理失败的情况。
比如,成功情况的处理函数为:
完成的代码如下:
做完之后的效果:
首先按照 (Content Editor Webpart(一)引用JQuery) 中的说明,引入JQuery。然后在Content Editor中添加代码。
比如要获取site的title 和description。
function retrieveWebSite(siteUrl) { var clientContext = new SP.ClientContext(siteUrl); this.oWebsite = clientContext.get_web(); clientContext.load(this.oWebsite); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); }
和Server OM不同的是,客户端OM,必须要先调用Load方法,再调用execute方法,才去与服务器交互。executeQueryAsync方法,定义了两个事件,一个是处理成功的情况,一个处理失败的情况。
比如,成功情况的处理函数为:
function onQuerySucceeded(sender, args) { alert('Title: ' + this.oWebsite.get_title() + ' Description: ' + this.oWebsite.get_description()); }
完成的代码如下:
<div style="height: 200px;">
<script type="text/javascript" src="/sites/apps/Style%20Library/jquery-1.10.2.min.js"></script><script>
function retrieveWebSite(siteUrl) { var clientContext = new SP.ClientContext(siteUrl); this.oWebsite = clientContext.get_web(); clientContext.load(this.oWebsite); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); }
function onQuerySucceeded(sender, args) { alert('Title: ' + this.oWebsite.get_title() + ' Description: ' + this.oWebsite.get_description()); }
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
</script>
<button id="#getInfo" onclick="retrieveWebSite(‘https://server/sites/site/internal’)">Get Site Info </button></div>
做完之后的效果:
相关文章推荐
- Content Editor Webpart(三)使用JSOM
- Content Editor Webpart(二)添加JQuery和html代码
- In-System Memory Content Editor使用
- Content Editor Webpart(一)引用JQuery
- quartus II工具In-System Memory Content Editor使用方法
- 使用WSS自带的Content Editor Web Part显示天气预报
- 使用WSS自带的Content Editor Web Part显示天气预报
- 『SharePoint』Content Editor Webpart不能添加引用_layouts下面的文件
- Content Editor Webpart(一)引用JQuery
- Content by query webpart 自定义样式的使用方法
- Unity Editor中使用AssetBundle里的shader遇到的问题
- ASP.NET 2.0中使用webpart系列控件
- GEF,EMF,RCP,Eclipse's plugin的几个问题(6) 推荐使用新版本的VE(Visual Editor)
- 使用@ViewChild @ViewChildren(ngAfterViewInit), @ViewChild@ViewChildren(ngAfterContentInit)
- ContentValues 的使用
- [Android]使用ImageView引起Missing contentDescription attribute on image的问题
- Asp.net MVC中关于@Html标签Label、Editor使用
- 关于PHP程序使用file_get_content()函数进行抓取PHP程序与smarty结合编译过程中产生的静态文件,抓取不了?连接超时?(地址映射)
- Android杂谈--内存泄露(1)--contentView缓存使用与ListView优化
- 在代码中使用Autolayout – intrinsicContentSize和Content Hugging Priority