I have a Document Library with multiple documents. One can select multiple documents even all the documents at a time.
I need to fetch the documents name which are selected in Javascript using JQuery & SPServices
First, I am able to get IDs which are selected using the following code

var context = SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);

So, I am getting the IDs which are selected, now I need to fetch the name of those documents by the IDs.
Guys can anyone please tell me what is the best way to do so.

有帮助吗?

解决方案

var context = SP.ClientContext.get_current();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);

var fileName = [];

for (var i = 0; i < selectedItems.length; i++) {
    var itemId = selectedItems[i].id;
    fileName[i] = GetName(itemId);
}

function GetName(itemId) {        
    var currentList = context.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList());
    this.singleItem = currentList.getItemById(itemId);

    context.load(this.singleItem, 'Name');
    context.executeQueryAsync(Function.createDelegate(this, this.OnSucceeded), Function.createDelegate(this, this.OnFailed));
}

function OnSucceeded() {
    this.NameValue = this.singleItem.get_item('Name');
}

function OnFailed(sender, args) {
    alert('Error occurred: ' + args.get_message());
}

Here I have added column 'Name', you can use any column you want as per requirement.

var fileName = []; 

this variable will give you list of all your selected document names

许可以下: CC-BY-SA归因
scroll top