下面是服务器端对象模型(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 |
以下示例演示如何创建列表。
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/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
以下示例显示如何"删除"列表项。
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()
{
//……比如计算某值
}
转:SharePoint 2013 使用JQuery 一些记录如(SharePoint js 获得当前用户)等基本操作。
原文:https://www.cnblogs.com/hanrend/p/14403981.html