JSOM是SharePoint 提供的一种clientAPI。开发者仅仅须要使用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不同的是,clientOM。必需要先调用Load方法。再调用execute方法。才去与server交互。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>

做完之后的效果:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvU1BGYXJt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

最新文章

  1. 用c#开发的一款webservice调用小工具,方便测试
  2. uboot补丁的分析
  3. mysql中判断记录是否存在方法比较
  4. CEPH浅析”系列之三——CEPH的设计思想
  5. XHTML基础
  6. 手机抓包-fiddler
  7. iTerm和Alfred 2的安装和使用
  8. 【软件工程】week5-个人作业-敏捷开发方法初窥
  9. 构建一个简单的Maven项目
  10. JSP 相关试题(五)
  11. php curl post
  12. 持久化框架Hibernate 开发实例(二)
  13. Android ListView快速定位(四)
  14. 李洪强iOS开发Swift篇—10_方法
  15. chkdsk
  16. 【wannacry病毒之暗网】-如何访问&quot;暗网&quot;(慎入)
  17. 利用Java随机,生成随机学生数据
  18. 如何使用iOS开发者授权以及如何申请证书
  19. eclipse 项目中嵌入jetty
  20. 走进JDK(二)------String

热门文章

  1. Hibernate 注解(Annotations 四)多对多双向注解
  2. 理解bind函数
  3. RabbitMq、ActiveMq、ZeroMq、kafka各个消息中间件之间的区别
  4. C语言——链式存储实现栈的基本运算算法
  5. &lt;Android 基础(二十四)&gt; EditText
  6. 【转】OmniGraffle (一)从工具栏开始
  7. CentOS7 安装 JIRA 7.2.x 教程:下载、安装、汉化、破解
  8. sql join实例图解
  9. python基础——操作系统简介
  10. Asp.Net MVC Identity 2.2.1 使用技巧(六)