SharePoint 2013 使用JQuery 一些记录如(SharePoint js 获得当前用户)等基本操作。

本文介绍了在SharePoint 2013中使用JQuery进行REST API操作,包括创建、更新和删除列表项,并展示了如何在前后台之间进行代码调用,包括C#调用前端JS函数和前端调用后台方法的多种方法。
摘要由CSDN通过智能技术生成

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()" />


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值