[英]How to move list item into folder in Sharepoint online
I created a folder and have some item in this list. 我创建了一个文件夹,并且此列表中有一些项目。 So now how can I move list item into folder using JSOM.
因此,现在如何使用JSOM将列表项移动到文件夹中。 I know user can drag/drop, but I want when user create a list is always move to folder automatically.
我知道用户可以拖放,但是我希望用户创建列表时始终自动将其移动到文件夹。
The following example demonstrates how to move a list item into folder via SharePoint JSOM API: 下面的示例演示如何通过SharePoint JSOM API将列表项移动到文件夹中:
var listTitle = "Requests"; //list title
var itemId = 1; //list item id
var targetFolderUrl = "/Lists/Requests/Archive"; //target folder server relative url
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listTitle);
var item = list.getItemById(itemId);
ctx.load(item,['FileRef','FileDirRef']);
ctx.executeQueryAsync(
function(){
var fileUrl = item.get_item('FileRef');
var file = ctx.get_web().getFileByServerRelativeUrl(fileUrl);
var targetfileUrl = fileUrl.replace(item.get_item('FileDirRef'),targetFolderUrl);
file.moveTo(targetfileUrl, SP.MoveOperations.overwrite);
ctx.executeQueryAsync(
function(){
console.log('List item has been moved');
},
logError
)
},
logError);
function logError(sender,args){
console.log(args.get_message());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.