0

I want to create a Webpart as image slider which contains the images from an image gallery. I want to show each image's description under it in the image slider. But have some problems regarding that: when I use REST API to retrieve the image description, there is no title or ID that I can address to find the images. Its just Items(1)/Items(2),... how I can find the images? If I add a scripts which retrieves the descriptions and add each of them to the sliding images in the Webpart, will that script applies to all images or just one of them during loading the page? Is there any better way to do implement that image slider?

2

what REST call were you using? You should have been able to get a whole bunch of items using OData filtering.

Something like this:

     var itemtitle = "Some Title"
        $.ajax({
                url: _spPageContextInfo.webServerRelativeUrl + 
                "_api/web/lists/getByTitle('Images')/Items?$select=Title,FileLeafRef,FileDirRef,Description&$filter=Title eq '" + itemtitle + "'",
                type: "GET",
                headers: {"accept": "application/json;odata=verbose"},
                success:  this.success,
                error: this.failed 
            }); 

      function success(data, args) {

        var results = data.d.results;
        // results are in an array format, 'Description' should be a parameter of that array index
        // var description = results[0].Description;

      }

I'd also have all the content of the webpart in an html page, referencing jquery and any other javascript files (there are several image rotator jQuery plugins you can use) and then use a content editor webpart to reference that html file.

  • this REST returns all items, I want to filter just one of them based on Title or ID. but there is nothing like Title or id in the REST! – Adi Apr 27 '16 at 9:31
  • I'll edit it to your liking. You can use that at the end of the REST call, using $filter see here to add to the REST call: odata.org/documentation/odata-version-2-0/uri-conventions/… – Mike Apr 27 '16 at 12:37
0

I would say using Client Side Rendering(CSR)/JSLink would be a right approach. That way you don't have to worry about querying list and can just focus on building the html. Below is a link for some of the code samples using CSR

https://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a

For the REST API approach, are you not able to get the image description column along with the Image/ImageURL? It would be helpful if you can post the REST URL you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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