这个示例里,我们将演示如何获取用户信息:
1. 打开 Visual Studio 2012.
2. 创建一个新的 SharePoint 2013 app: UserProfileTest.
3. 选择SharePoint-hosted, 点Finish.
4. 打开Default.aspx :
加入knockoutjs和sp.userprofiles.debug.js(包含user profile的信息):
<script type="text/javascript" src="../Scripts/knockout-3.0.0.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.debug.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.debug.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.userprofiles.debug.js"></script>
修改title:
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
User Information
</asp:Content>
加入用户显示:
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server"> <h2>Current User Properties</h2> <table data-bind="with: currentUser"> <tr> <td>title</td> <td data-bind="text: get_title()"></td> </tr> <tr> <td>Id</td> <td data-bind="text: get_id()"></td> </tr> <tr> <td>loginName</td> <td data-bind="text: get_loginName()"></td> </tr> <tr> <td>email</td> <td data-bind="text: get_email()"></td> </tr> <tr> <td>isSiteAdmin</td> <td data-bind="text: get_isSiteAdmin()"></td> </tr> </table> </asp:Content>
5. 打开App.js 修改如下:
前二行引用的js提供了智能感知的功能
/// <reference path="knockout-3.0.0.debug.js" /> /// <reference path="~/_layouts/15/sp.userprofiles.debug.js" /> $(function () { ko.applyBindings(new userProfileProps()); }); function userProfileProps() { var self = this; self._currentUser = null; self.currentUser = ko.observable(); self.load = function () { var context = SP.ClientContext.get_current(); self._currentUser = context.get_web().get_currentUser(); context.load(self._currentUser); var pm = new SP.UserProfiles.PeopleManager(context); self._props = pm.getMyProperties(); context.load(self._props); context.executeQueryAsync( Function.createDelegate(self, self.onSuccess), Function.createDelegate(self, self.onFail) ); } self.onSuccess = function () { self.currentUser(self._currentUser); } self.onFail = function (sender, args) { alert("Unable to access user information: " + args.get_message()); } self.load(); }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索context
, function
, load
, 用户
, knockoutjs
, Self
, 示例
, knockoutjs绑定
, 获取context
, knockoutjs分页
knockoutjs教程
微信开发获取用户信息、微信开发获取用户头像、微信开发获取用户列表、开发者获取用户openid、sharepoint开发培训,以便于您获取更多的相关知识。