SharePoint 2013 使用JQuery 一些记录。
REST API 引用和示例
https://msdn.microsoft.com/zh-cn/library/jj860569.aspx
Rest API
https://msdn.microsoft.com/zh-cn/magazine/dn198245.aspx
sharepoint Js 获得当前用户
this.context = new SP.ClientContext.get_current();
this.web = this.context.get_web();
this.currentUser = this.web.get_currentUser();
this.currentUser.retrieve();
var _spUserId= _spPageContextInfo.userId
currentcontext.load(currentweb);
var login = user.get_loginName();
下面是服务器端对象模型(Microsoft.SharePoint.dll)与JS对象模型的比较图:
服务器端对象模型 |
JS对象模型 |
Microsoft.SharePoint.SPContext |
SP.ClientContext |
Microsoft.SharePoint.SPSite |
SP.Site |
Microsoft.SharePoint.SPWeb |
SP.Web |
Microsoft.SharePoint.SPList |
SP.List |
Microsoft.SharePoint.SPListItem |
SP.ListItem |
Microsoft.SharePoint.SPField |
SP.Field |
参加地址:https://msdn.microsoft.com/en-us/library/office/jj246815.aspx
<script type="text/ecmascript" language="ecmascript">
var fieldCollection;
var oneField = null;
function runCode() {
var clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
taskList = webSite.get_lists().getByTitle("Tasks");
fieldCollection = taskList.get_fields();
this.oneField = fieldCollection.getByInternalNameOrTitle("Title");
this.oneField.set_description("MyNewFieldDescription");
this.oneField.update();
clientContext.load(this.fieldCollection);
clientContext.load(this.oneField);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args) {
var fieldInfo = '';
fieldInfo += 'Field Title: ' + oneField.get_title() + '\n' + 'Description: ' + oneField.get_description() + '\n';
alert(fieldInfo);
}
function OnLoadFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
<input id="Button1" type="button" value="Run Code" οnclick="runCode()" />