[英]Copy selected List-Items to an other list with ECMA Script
i need a script that copies all my selected list items to an other (custom) list. 我需要一个脚本,将所有我选择的列表项复制到另一个(自定义)列表。 I found nice solution for documents:
我找到了很好的文档解决方案:
var context = SP.ClientContext.get_current();
var web = context.get_web();
context.load(web);
var _destinationlib = web.get_lists().getByTitle('DestinationLibrary');
context.load(_destinationlib);
var notifyId;
var currentlibid = SP.ListOperation.Selection.getSelectedList();
var currentLib = web.get_lists().getById(currentlibid);
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
var count = CountDictionary(selectedItems);
for(var i in selectedItems)
{
alert('Now copying ' + i);
var currentItem = currentLib.getItemById(selectedItems[i].id);
context.load(currentItem);
var File = currentItem.get_file();
context.load(File);
//Excecuting executeQueryAsync to get the loaded values
context.executeQueryAsync
(
function (sender, args) {
if(File != null) {
var _destinationlibUrl = web.get_serverRelativeUrl() + _destinationlib.get_title() + '/' + File.get_name();
File.copyTo(_destinationlibUrl, true);
notifyId = SP.UI.Notify.addNotification('Moving file…' + File.get_serverRelativeUrl() + 'to' + _destinationlibUrl, true);
//Excecuting executeQueryAsync to copy the file
context.executeQueryAsync(
function (sender, args) {
SP.UI.Notify.removeNotification(notifyId);
SP.UI.Notify.addNotification('File copied successfully', false);
},
function (sender, args) {
SP.UI.Notify.addNotification('Error copying file', false);
SP.UI.Notify.removeNotification(notifyId);
showError(args.get_message());
});
}
},
function (sender, args) {
alert('Error occured' + args.get_message());
}
);
}
I dont know what i have to change to get it working for normal list items. 我不知道我要更改使其正常列表项工作。 I tried to exchange
我试图交流
var File = currentItem.get_file();
context.load(File);
with 与
var title = currentItem.get_Title();
context.load(title);
var number = currentItem.get_item('number');
context.load(number);
but it dosnt work. 但它没有用。 It would be great if somebody can give me a hint what i have to do.
如果有人可以给我提示我必须做的事,那就太好了。
many thx 许多
Fabulus bul
It looks like that you took code above from here . 看来您是从此处获取了上面的代码。
Try to be attentively. 努力专心。 This code copies selected files (not list items!) to another document library!
此代码将所选文件(不是列表项!)复制到另一个文档库!
For your needs better try to code your own solution. 为了您的需求,最好尝试编写自己的解决方案。 See SharePoint JavaScript Class Library for details.
有关详细信息,请参见SharePoint JavaScript类库 。 You can have two possible architectures:
您可以有两种可能的体系结构:
Also be careful with context.load. 也要注意context.load。 It's recommended to write all next code in context.executeQueryAsync.
建议在context.executeQueryAsync中编写所有下一个代码。 Use Firebug in FF and developer tools in Chrome for debugging your code and to find what is wrong.
使用FF中的Firebug和Chrome中的开发人员工具来调试代码并找出问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.