SharePoint 2013 - Client OM
1. 向 executeQueryAsync 中传递参数可以使用以下两种方式,也可以参考这篇文章:
var mySuccessCallBack = Function.createCallback(onQuerySucceeded, oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, mySuccessCallBack),Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded(sender, args, item){
alert("Added"+ item.get_id());
} function onQueryFailed(sender, args){
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
或者:
clientContext.executeQueryAsync(Function.createDelegate(this, function(){onQuerySucceeded(oListItem);}), Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded(item){
alert("Added"+ item.get_id());
}
function onQueryFailed(sender, args){
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
2. 下面代码演示了SharePoint 2013 中如何使用 client-side people picker control 并获取用户信息,参考链接;
引用内置JS文件:(注意,在content edit webpart 中最好不要使用 <SharePoint:ScriptLink name="clienttemplates.js" runat="server" LoadAfterUI="true" Localizable="false" /> 来引用内置文件,因为<SharePoint:ScriptLink>需要包含在<asp:Content>标签内,在Content Edit Webpart内使用时,可能不起作用)
<script type="text/javascript" src="/_layouts/15/clienttemplates.js"></script>
<script type="text/javascript" src="/_layouts/15/clientforms.js"></script>
<script type="text/javascript" src="/_layouts/15/autofill.js"></script>
<script type="text/javascript" src="/_layouts/15/clientpeoplepicker.js"></script>
JavaScript:
<script type="text/javascript" src="/angularJS/SiteAssets/Scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
// Run your custom code when the DOM is ready.
$(document).ready(function () {
// Specify the unique ID of the DOM element where the
// picker will render.
initializePeoplePicker('peoplePickerDiv');
}); // Render and initialize the client-side People Picker.
function initializePeoplePicker(peoplePickerElementId) {
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = true;
schema['MaximumEntitySuggestions'] = 50;
schema['Width'] = '280px'; // Render and initialize the picker.
// Pass the ID of the DOM element that contains the picker, an array of initial
// PickerEntity objects to set the picker value, and a schema that defines
// picker properties.
this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
} // Query the picker for user information.
function getUserInfo() {
// Get the people picker object from the page.
var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan; // Get information about all users.
var users = peoplePicker.GetAllUserInfo();
var userInfo = '';
for (var i = 0; i < users.length; i++) {
var user = users[i];
for (var userProperty in user) {
userInfo += userProperty + ': ' + user[userProperty] + '<br>';
}
}
$('#resolvedUsers').html(userInfo); // Get user keys.
var keys = peoplePicker.GetAllUserKeys();
$('#userKeys').html(keys); // Get the first user's ID by using the login name.
getUserId(users[0].Key);
} // Get the user ID.
function getUserId(loginName) {
var context = new SP.ClientContext.get_current();
this.user = context.get_web().ensureUser(loginName);
context.load(this.user);
context.executeQueryAsync(
Function.createDelegate(null, ensureUserSuccess),
Function.createDelegate(null, onFail)
);
} function ensureUserSuccess() {
$('#userId').html(this.user.get_id());
} function onFail(sender, args) {
alert('Query failed. Error: ' + args.get_message());
}
</script>
HTML:
<div id="peoplePickerDiv"></div>
<div>
<br/>
<input type="button" value="Get User Info" onclick="getUserInfo()"></input>
<br/>
<h1>User info:</h1>
<p id="resolvedUsers"></p>
<h1>User keys:</h1>
<p id="userKeys"></p>
<h1>User ID:</h1>
<p id="userId"></p>
</div>
3.
SharePoint 2013 - Client OM的更多相关文章
- SharePoint 2013 - Client Side Rendering
1. Client side rendering 代码结构为: (function () { // Create object that have the context information ab ...
- SharePoint 2013 版本功能对比
前言:在SharePoint使用中,经常纠结于版本问题,SharePoint 2013主要有免费的Foundation和收费的标准版.企业版三个版本,他们之间的功能上是不一样的,找了一些资料才发现下面 ...
- SharePoint 2013版本功能对比介绍
转:http://www.fengfly.com/plus/view-213720-1.html 在SharePoint使用中,经常纠结于版本问题,SharePoint 2013主要有免费的Found ...
- Integrating SharePoint 2013 with ADFS and Shibboleth
Time again to attempt to implement that exciting technology, Federation Services (Web Single Sign On ...
- SharePoint 2013 Excel Services ECMAScript 示例之明日限行
前言:最近遇到一个“明日限行”的功能,北京的交通啊,这个不在今天讨论范围内,暂不吐槽,想想代码开发,还要写WebPart部署,很麻烦,而且部署服务器,需要领导审批,想绕过这个麻烦事儿,就想到客户端了, ...
- SharePoint 2013技巧分享系列 - 同步Exchange显示高清用户照片
在“SharePoint 2013技巧分享系列 - Active Directory同步显示用户照片”文中介绍了如何同步Active Directory显示用户照片,但是同步完成后,用户照片尺寸和清晰 ...
- SharePoint 2013常用开发工具分享
众所周知,一款好的开发工具不仅能提高项目开发效率,而且能够协助开发人员简化开发流程.本文汇总几款SharePoint 2013开发常用开发工具,希望能够对大家有所帮助.如果您有更好的工具,没有包含在本 ...
- 在Windows Server 2012 R2上安装SharePoint 2013 with SP1失败,提示没有.net4.5的解决办法
现在的Server用Windows Server 2012 R2的越来越多了,在部署带Sp1的SharePoint2013的时候,走完预安装工具后,点击setup提示缺少.net4.5. 其实Wind ...
- SharePoint 2013 中的 PowerPoint Automation Services
简介 许多大型和小型企业都将其 Microsoft SharePoint Server 库用作 Microsoft PowerPoint 演示文稿的存储库.所有这些企业在 ...
随机推荐
- C语言学习总结(1)——结构体
一,什么是结构体 我们知道数组(Array),它是一组具有相同类型的数据的集合.但在实际的编程过程中,我们往往还需要一组类型不同的数据,例如对于学生信息登记表,姓名为字符串,学号为整数,年龄 ...
- mfix添加文件后重新生成configure文件
mfix给了一些程序接口,大部分时候只用修改现有程序即可满足要求,这种情况不用修改configure文件,但是如果添加了新文件就需要做一些修改. 我用了Jian Cai的程序尝试了一下编译,该学者在2 ...
- Django - Xadmin 组件(二)
Django 自带的 admin 组件可以自定义配置,本文实现 Xadmin 对自定义显示数据列 (list_display) 的配置. 构建表单数据 模板层 从视图函数传来的数据变量是双层列表,第一 ...
- A计划(三维dfs)
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚,告招天下 ...
- 2016 ccpc 杭州 D.Difference hdu5936(折半枚举)
有坑!!!当x==0时,因为y>0,a,b不能同时为0,所以答案要-1 #include<iostream> #include<cstdlib> #include< ...
- Wscript.Shell 对象详细介绍
详细 WshShell 对象ProgID Wscript.Shell 文件名 WSHom.Ocx CLSID F935DC22-1CF0-11d0-ADB9-00C04FD58A0B IID F935 ...
- Firefox与IE浏览器缓存的两个重要区别
转自: http://www.yeeyan.org/articles/view/mouse4x/17150 当你建立好一个WEB服务后,通常有两个类型的缓存需要配置: 设置网站有更新的时候html资源 ...
- 对avalonjs的研究
<!DOCTYPE html> <html> <head> <title>第一个avalon项目</title> <meta char ...
- Lucene常用类
1.1 IndexWriter: 充当 创造/在索引过程中更新指标的 核心组成部分 1.2 Lucene目录 Directory: 索引的存储位置: 通常是文件的列表: 这些文件被称为索引文件. ...
- 抽象工厂方法模式(Abstract Factory Pattern)
Provide an interface for creating families of related or dependent objects without specifying their ...