Content Editor Webpart(三)使用JSOM
2024-08-28 10:53:24
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="">
最新文章
- 用c#开发的一款webservice调用小工具,方便测试
- uboot补丁的分析
- mysql中判断记录是否存在方法比较
- CEPH浅析”系列之三——CEPH的设计思想
- XHTML基础
- 手机抓包-fiddler
- iTerm和Alfred 2的安装和使用
- 【软件工程】week5-个人作业-敏捷开发方法初窥
- 构建一个简单的Maven项目
- JSP 相关试题(五)
- php curl post
- 持久化框架Hibernate 开发实例(二)
- Android ListView快速定位(四)
- 李洪强iOS开发Swift篇—10_方法
- chkdsk
- 【wannacry病毒之暗网】-如何访问";暗网";(慎入)
- 利用Java随机,生成随机学生数据
- 如何使用iOS开发者授权以及如何申请证书
- eclipse 项目中嵌入jetty
- 走进JDK(二)------String
热门文章
- Hibernate 注解(Annotations 四)多对多双向注解
- 理解bind函数
- RabbitMq、ActiveMq、ZeroMq、kafka各个消息中间件之间的区别
- C语言——链式存储实现栈的基本运算算法
- <;Android 基础(二十四)>; EditText
- 【转】OmniGraffle (一)从工具栏开始
- CentOS7 安装 JIRA 7.2.x 教程:下载、安装、汉化、破解
- sql join实例图解
- python基础——操作系统简介
- Asp.Net MVC Identity 2.2.1 使用技巧(六)