1

This is my simple application in this application I fetch the SharePoint Document Library please see the code now I want to show only particular item in Library when user click on any document name.

When user click in document name my sharepoint site must open and show my Document lib.

    function StoreInArray() {
    var CallLibrary = GetListItems();
    $.when(CallLibrary).then(function (FilesData) {
        for (var i = 0; i < FilesData.d.results.length; i++) {

            var name = FilesData.d.results[i].Name;
            var url = FilesData.d.results[i].ServerRelativeUrl;
            var newDiv = document.createElement('div');
                // Here I show document name and create link to open the sharepoint site 
            $('#DocName').append("<div><a href='' >" + name + "</a></div>");

        }
    });
}

function GetListItems() {
    var siteURL = "http://localhost:8032/_api/web/GetFolderByServerRelativeUrl('docList')/Files";
    return $.ajax({
        url: siteURL,
        async: false,
        method: "GET",
        headers: { "Accept": "application/json;odata=verbose" }
    });
  }

1 Answer 1

1

Hello Please check below code...

 function StoreInArray() {
    var CallLibrary = GetListItems();
    $.when(CallLibrary).then(function (FilesData) {
        for (var i = 0; i < FilesData.d.results.length; i++) {

            var name = FilesData.d.results[i].Name;
            var url = FilesData.d.results[i].ServerRelativeUrl;
            var newDiv = document.createElement('div');
                // Here I show document name and create link to open the sharepoint site 
            $('#DocName').append("<div><a href='" + url + "' >" + name + "</a></div>");

        }
    });
}
1
  • 1
    $.when is for multiple Promises; since you are only doing one you can simply to: GetListItems().then(.... Feb 21, 2017 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.