zoukankan      html  css  js  c++  java
  • SharePoint 使用Jquery

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
    本文链接:https://blog.csdn.net/jason_dct/article/details/51479578
    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() + ' ' + 'Description: ' + oneField.get_description() + ' ';
    alert(fieldInfo);
    }

    function OnLoadFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + ' ' + args.get_stackTrace());
    }
    </script>

    <input id="Button1" type="button" value="Run Code" οnclick="runCode()" />

     通过 REST 使用列表
    以下示例演示如何创建列表。

    url: http://site url/_api/web/lists
    method: POST
    body: { '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 100,
    'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Test' }
    Headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
    content-length:length of post body
    以下示例演示如何使用 MERGE 方法更新列表。

    url: http://site url/_api/web/lists(guid'list GUID')
    method: POST
    body: { '__metadata': { 'type': 'SP.List' }, 'Title': 'New title' }
    Headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    IF-MATCH": etag or "*"
    X-HTTP-Method: MERGE,
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
    content-length:length of post body
    以下示例演示如何为列表创建自定义字段。

    Url: url: http://site url/_api/web/lists(guid'list GUID')/Fields
    Method:POST
    Body: { '__metadata': { 'type': 'SP.Field' }, 'Title': 'field title', 'FieldTypeKind': FieldType value,'Required': 'true/false', 'EnforceUniqueValues': 'true/false','StaticName': 'field name'}
    Headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    content-type: "application/json;odata=verbose"
    content-length:length of post body
    以下示例演示如何删除列表。

    url: http://site url/_api/web/lists(guid'list GUID')
    method: POST
    Headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    IF-MATCH: etag or "*"
    X-HTTP-Method: DELETE

     通过 REST 使用列表项
    以下示例显示如何"检索"列表的所有项。

    url: http://site url/_api/web/lists/GetByTitle(‘Test')/items
    method: GET
    headers:
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or "application/atom+xml"

    以下示例显示如何"检索"特定列表项。

    url: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)
    method: GET
    headers:
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or "application/atom+xml"

    以下 XML 显示当您请求 XML 内容类型时返回的列表项属性的示例。

    <content type="application/xml">
    <m:properties>
    <d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
    <d:Id m:type="Edm.Int32">1</d:Id>
    <d:ID m:type="Edm.Int32">1</d:ID>
    <d:ContentTypeId>0x010049564F321A0F0543BA8C6303316C8C0F</d:ContentTypeId>
    <d:Title>an item</d:Title>
    <d:Modified m:type="Edm.DateTime">2012-07-24T22:47:26Z</d:Modified>
    <d:Created m:type="Edm.DateTime">2012-07-24T22:47:26Z</d:Created>
    <d:AuthorId m:type="Edm.Int32">11</d:AuthorId>
    <d:EditorId m:type="Edm.Int32">11</d:EditorId>
    <d:OData__UIVersionString>1.0</d:OData__UIVersionString>
    <d:Attachments m:type="Edm.Boolean">false</d:Attachments>
    <d:GUID m:type="Edm.Guid">eb6850c5-9a30-4636-b282-234eda8b1057</d:GUID>
    </m:properties>
    </content>
    以下示例显示如何"创建"列表项。


    url: http://site url/_api/web/lists/GetByTitle(‘Test')/items
    method: POST
    body: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'Test'}
    headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
    content-length:length of post body
    以下示例显示如何"更新"列表项。


    url: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)
    method: POST
    body: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'TestUpdated'}
    headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    "IF-MATCH": etag or "*"
    "X-HTTP-Method":"MERGE",
    accept: "application/json;odata=verbose"
    content-type: "application/json;odata=verbose"
    content-length:length of post body
    以下示例显示如何"删除"列表项。

    url: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)
    method: POST
    headers:
    Authorization: "Bearer " + accessToken
    X-RequestDigest: form digest value
    "IF-MATCH": etag or "*"
    "X-HTTP-Method":"DELETE"

    1,读取SharePoint list 标题后删除最后一个字。
    var s2=tText.substr(0,tText.length-1);
    alert(s2);

    效果

    JS URL 解码

     //解码
             var s9=("http://portal.com.cn/_layouts/15/AD/adPicker.aspx?ou=%E9%BB%84%E6%B2%B3%E6%B0%B4%E7%94%B5&IsDlg=1");
              alert(decodeURI(s9));
              //弹出来的是解码后的原始结果。

    前后台代码互相调用
    C#前台js调用后台代码
    前台js
    <script type="text/javascript" language="javascript">
      function Ceshi()
      {
        var a = "<%=Getstr()%>";
        alert(a);
      }
    </script>
    <input type="button" οnclick="Ceshi();" value="js调用后台代码" />
    后台代码
    public string Getstr()
    {
      string aa = "你们好啊!";
      return aa;
    }

    C#后台调用前台js代码
    前台js
    <script type="text/javascript" language="javascript">
      function Ceshi()
      {
        var a = "你们好啊!"
        alert(a);
      }
    </script>
    <asp:Button ID="Button1" runat="server" Text="后台调用js" οnclick="Button1_Click" />
    后台代码
    protected void Button1_Click(object sender, EventArgs e)
        {
        //如果有UpdatePanel就用如下代码调用前台js
        ScriptManager.RegisterStartupScript(UpdatePanel1, this.Page.GetType(), "", "Ceshi();", true);
        //如果没有就如下代码
        this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "<script>Ceshi();</script>", true);
        }

    javascript函数中执行C#代码中的函数:
    方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中;
            2、在前台写一个js函数,内容为document.getElementByIdx("btn1").click();--母版页:  document.getElementById("<%=txtName.ClientID%>");
            3、在前台或后台调用js函数,激发click事件,等于访问后台c#函数;

    方法二:1、函数声明为public             
                后台代码(把public改成protected也可以)
               public string ss()
                {
                  return("a");
                }
            2、在html里用<%=fucntion()%>可以调用
                前台脚本
               <script language=javascript>
                var a = "<%=ss()%>";
                alert(a);
               </script>
    方法三:1、<script language="javascript">
               <!- -
                function __doPostBack(eventTarget, eventArgument)
                {
                   var theForm = document.Form1;     //指runat=server的form
                   theForm.__EVENTTARGET.value = eventTarget;
                   theFrom.__EVENTARGUMENT.value = eventArgument;
                   theForm.submit();
                }
               -->
               </script>
               <input id="Button1" type="button" name="Button1" value="按钮" οnclick="javascript:__doPostBack('Button1','')">
            
    方法四:<script language="javascript">
    function SubmitKeyClick()
    {
        if (event.keyCode ==13)
         {
            event.cancelBubble = true;
            event.returnValue = false;
             document.all.FunName.value="你要调用的函数名";
             document.form[0].submit();
         }
    }
    </script>

    <INPUT οnkeypress="SubmitKeyClick()" id="aaa" type="text">
    <input type="hidden" name="FunName"> 〈!--用来存储你要调用的函数 --〉

    在.CS里有:
    public Page_OnLoad()
    {
    if (!Page.IsPost())
    {
    string strFunName=Request.Form["FunName"]!=null?Request.Form["FunName"]:"";
    //根据传回来的值决定调用哪个函数
    switch(strFunName)
    {
    case "enter()":
    enter() ; //调用该函数
    break;
    case "其他":
    //调用其他函数
    break;
    default:
    //调用默认函数
    break;
    }
    }
    }

    public void enter()
    {
    //……比如计算某值
    }

    ————————————————
    版权声明:本文为CSDN博主「段传涛」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/duanchuanttao/article/details/51479578

  • 相关阅读:
    Angular $http解析通过接口获得的json数据
    Python基础(十四)—装饰器 wrapper
    Python基础(十二)—面向对象拾遗(__slots__、@property、枚举类、元类)
    Python基础(十三)—切片、yield、生成器、序列化JSON
    Python基础(十一)—魔法方法(构造析构、属性魔法、算数魔法、类型魔法等)
    Python基础(十)—面向对象的深入讲解(继承、Mixin编程机制等)
    Python基础(九)—异常except、else&with、异常的名称层次
    Python基础(八)—编码详解(ASCII、GBK、Unicode、UTF-8等)、decode&encode
    Python基础(七)—输入输出(open、os、pickle)
    Python基础(六)—函数式编程(内部函数、闭包、lambda、filter/map/reduce/sorce、偏函数)
  • 原文地址:https://www.cnblogs.com/xdanny/p/11456764.html
Copyright © 2011-2022 走看看