Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.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 处理多个sharepoint列表项_Javascript_Sharepoint 2010_Sharepoint Clientobject - Fatal编程技术网

Javascript 处理多个sharepoint列表项

Javascript 处理多个sharepoint列表项,javascript,sharepoint-2010,sharepoint-clientobject,Javascript,Sharepoint 2010,Sharepoint Clientobject,在SharePoint列表视图中,我希望复制选定的列表项。我的代码在仅选择一个项目时有效,但在选择更多项目时失败。调试代码时,我看到它在调用成功回调之前首先遍历了所有选定的项。此外,在成功回调中,currItem并不总是填充项目数据 如何逐个获取和处理所选项目 function copySelected(){ if($("#copyAllButton").hasClass('ms-cui-disabled')){ return; } var cc = null; var web = nu

在SharePoint列表视图中,我希望复制选定的列表项。我的代码在仅选择一个项目时有效,但在选择更多项目时失败。调试代码时,我看到它在调用成功回调之前首先遍历了所有选定的项。此外,在成功回调中,currItem并不总是填充项目数据

如何逐个获取和处理所选项目

function copySelected(){
if($("#copyAllButton").hasClass('ms-cui-disabled')){
    return;
}
var cc = null;
var web = null;
copyCounter = 0;
failedCounter = 0;
cc = new SP.ClientContext.get_current();
web = cc.get_web();
var currItem = null;
notifyId = SP.UI.Notify.addNotification(duplicatingItemsNotification, true);
var selectedItems; 
currList = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
selectedItems = SP.ListOperation.Selection.getSelectedItems();
if( selectedItems.length > 0 ){
    for(var i in selectedItems){
        //var currItemID = selectedItems[i].id;
        currItem = currList.getItemById(selectedItems[i].id);
        cc.load(currItem);
        cc.executeQueryAsync(function(sender, args){
            var itemCreateInfo = new SP.ListItemCreationInformation();
            var aListItem = currList.addItem(itemCreateInfo);
                aListItem.set_item('Title', currItem.get_item('Title'));
                aListItem.set_item('Customer', currItem.get_item('Customer'));
                aListItem.set_item('Description', currItem.get_item('Description'));
                aListItem.set_item('Source', currItem.get_item('Source'));
                aListItem.set_item('field2', currItem.get_item('field2'));
                aListItem.set_item('field3', currItem.get_item('field3'));
                aListItem.set_item('Workloadtype', currItem.get_item('Workloadtype'));
                aListItem.set_item('Tickettype', currItem.get_item('Tickettype'));
                aListItem.set_item('Customergroup', currEngineer.group);
                aListItem.set_item('Allocation', currEngineer.allocation);
                aListItem.set_item('SubCap', currItem.get_item('SubCap'));
                aListItem.set_item('Engineer', currEngineer.fullName);
                aListItem.update();
                cc.load(aListItem);
                cc.executeQueryAsync(function(){
                    copyCounter ++;
                },function(){
                    failedCounter ++;
                });
        }, Function.createDelegate(this,this.getItemFailed));
    }
    notifyMe();
}

}

与此同时,我找到了解决方案(为这个问题重新思考这个问题很好)

我用查询填充所需项的数组,然后处理该数组

 var allSelectedItems;

 function copySelected(){
if($("#copyAllButton").hasClass('ms-cui-disabled')){
    return;
}
var cc = null;
var web = null;
copyCounter = 0;
failedCounter = 0;
cc = new SP.ClientContext.get_current();
web = cc.get_web();
//var currItem = null;
notifyId = SP.UI.Notify.addNotification(duplicatingItemsNotification, true);
var selectedItems; 
currList = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());
selectedItems = SP.ListOperation.Selection.getSelectedItems();
if( selectedItems.length > 0 ){
    allSelectedItems = new Array(selectedItems.length);
    for(var i in selectedItems){
        allSelectedItems[i] = currList.getItemById(selectedItems[i].id);
        cc.load(allSelectedItems[i]);
    }
    cc.executeQueryAsync(Function.createDelegate(this, this.getItemSucceded), Function.createDelegate(this, this.getItemFailed));
    notifyMe();
}
}