使用REST API使用ViewFields创建SharePoint 2013列表视图 [英] Create SharePoint 2013 list view with ViewFields using REST API
问题描述
大家好
我正在尝试使用REST API使用ViewFields创建SharePoint 2013列表视图.
I am trying to create a SharePoint 2013 list view with ViewFields using REST API.
我能够使用REST API创建视图,但是如何在单个REST调用中在该视图内添加多个ViewField?
I am able to create the view using REST API but how to add multiple ViewField within that view in a single REST call?
下面是我的使用REST API创建视图的代码示例.
Below is my code example to create the view using REST API.
现在,我无法在此REST调用中添加多个viewField.
Now I am not able to add multiple viewField within this REST call.
我能够使用JSOM创建具有多个视场的列表视图,但我想知道使用单个REST调用是否可能.
I am able to create list view with multiple viewfield using JSOM but I want to know is it possible using single REST call.
谁能帮我这个忙吗?
感谢你的帮助.预先感谢.
Appreciate your help. Thanks in advance.
推荐答案
以下是使用JavaScript将视图字段添加到列表视图的代码段:
Here is a code snippet adding view fields to list view using JavaScript:
<script type="text/javascript" src="/_layouts/15/JS/jquery.min.js"></script>
<script type="text/javascript">
function AddFieldToView() {
var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('MyList2')/Views(guid'8a5b60ac-e937-435c-959a-0613cef931df')/ViewFields/AddViewField";
var headers = {
"accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
};
var call = jQuery.ajax({
url: endPointUrl,
type: "POST",
data: JSON.stringify({
//your field
'strField': 'F2'
}),
headers: headers
});
call.done(function (data, textStatus, jqXHR) {
alert("View Updated Successfully");
});
call.fail(function (data, errorcode, errormessage) {
alert(JSON.stringify(data));
});
}
</script>
谢谢
最好的问候
这篇关于使用REST API使用ViewFields创建SharePoint 2013列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!