Content Editor Webpart(三)使用JSOM
来源:互联网 发布:java源文件的扩展名是 编辑:程序博客网 时间:2024/06/05 19:27
JSOM是SharePoint 提供的一种客户端API。开发人员只需要使用Javescript,就可以实现和SharePoint的交互,非常方便。
首先按照 (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>
做完之后的效果:
0 0
- Content Editor Webpart(三)使用JSOM
- Content Editor Webpart(一)引用JQuery
- Content Editor Webpart(二)添加JQuery和html代码
- In-System Memory Content Editor使用
- 使用WebPart的三种方式
- webPart的使用(转载——)
- 开发自己的SQL2005报表查看SharePoint WebPart(三)
- In-System Memory Content Editor
- 使用Feature导入WebPart
- webPart的简单使用
- 使用QuickPart开发WebPart
- Add Script Editor and Content Editor Web Part via powershell
- WebPart学习(转)
- WebPart
- webpart
- webpart
- eclipse错误 -- Unsupported content type in editor.
- 使用WebPart 来包装ActiveX
- 设计模式学习(三) -- 工厂模式 Factory Pattern
- ubuntu下python升级
- C# 下读写VF数据库
- maven 手动安装本地jar到仓库
- 插入排序
- Content Editor Webpart(三)使用JSOM
- 改变ViewPager滑动速度
- Android DiskLruCache完全解析,硬盘缓存的最佳方案
- javascript中如何让类工厂和构造函数变成同一个函数
- maven学习(下)利用Profile构建不同环境的部署包
- android下拉菜单spinner的使用方法
- 微信110来啦!
- 欢迎使用CSDN-markdown编辑器
- 图像二值化--阈值自动选取