Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ECMA脚本将所选列表项复制到其他列表_Javascript_Sharepoint_Sharepoint 2010 - Fatal编程技术网

Javascript 使用ECMA脚本将所选列表项复制到其他列表

Javascript 使用ECMA脚本将所选列表项复制到其他列表,javascript,sharepoint,sharepoint-2010,Javascript,Sharepoint,Sharepoint 2010,我需要一个脚本,可以将所有选定的列表项复制到其他(自定义)列表。我找到了很好的文档解决方案: 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 n

我需要一个脚本,可以将所有选定的列表项复制到其他(自定义)列表。我找到了很好的文档解决方案:

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());
}
);
}
我不知道我必须改变什么才能让它为正常的列表项工作。我试着交换

var File = currentItem.get_file();

context.load(File);

但它不起作用。如果有人能给我一个提示我该做什么就好了

许多thx


Fabulus

看起来您是从上面的代码中获取的

尽量专心。此代码将所选文件(而不是列表项!)复制到另一个文档库

为了满足您的需求,最好尝试编写自己的解决方案。有关详细信息,请参阅。您可以有两种可能的体系结构:

  • 使用JavaScript完成所有工作。你迈出的第一步就是
  • 在JavaScript中处理客户端上的选择,并调用自定义服务器端组件(可能是应用程序页面)进行项目复制(在初始列表中已存在项目的新列表中创建副本)。例如,见
  • 还要注意context.load。建议在context.executeQueryAsync中编写接下来的所有代码。使用FF中的Firebug和Chrome中的开发者工具调试代码并找出错误

    var title = currentItem.get_Title();
    context.load(title);
    
    var number = currentItem.get_item('number');
    context.load(number);