简体   繁体   English

单击图像时,我正在尝试从 Sharepoint 列表中检索信息

[英]I am trying to retrieve information from a Sharepoint list when clicking an image

I have a Sharepoint list with 3 columns: Image, Title, and Description.我有一个包含 3 列的 Sharepoint 列表:图像、标题和描述。 I am trying to retrieve the items via ajax.我正在尝试通过 ajax 检索项目。 The images I can get successfully and the idea is that when I click on the images I retrieve the title and description for the clicked image.我可以成功获得的图像,想法是当我单击图像时,我会检索单击图像的标题和描述。 What I am getting in the console, after clicking the image,is the first title and first description on the list regardless of the images I click on.在单击图像后,我在控制台中得到的是列表中的第一个标题和第一个描述,而不管我单击的图像是什么。 After clicking the image, the title and description must append to a div with the id of #captionContainer.点击图片后,标题和描述必须 append 到一个id为#captionContainer的div。

var buildMainCarousel = function (items) {
    var flickitySlider = $('#flickityCarousel');
    var carouselContent;

    for (var i = 0; i < items.length; i++) {
        carouselContent = '<div class="carousel-cell">' +
            '<img src=" ' + items[i].Image.Url.replace("http://bc-net", "") + '"" alt="">' +
            '</div>';
        console.log(carouselContent);
        flickitySlider.append(carouselContent);
    }

};

var buildCaptions = function (items) {
    var captionContainer = $('#captionContainer');

 $(".carousel-cell img").click(function() {
    var clickedThumb= $(this);
        var title = items[i].Title;
        var description = items[i].Description;
       console.log(title);
        console.log(description);

});

};
var url1 = "/FunZone/_api/web/lists/GetByTitle('funZone')/items";
var handle_ajax = function (url) {
    $.ajax({
        url: url,
        method: "GET",
        headers: {
            Accept: "application/json; odata=verbose"
        },
        success: function (data) {
            var items = data.d.results;
            console.log(items);

            buildMainCarousel(items);
            buildCarouselNav(items);
            buildCaptions(items);
        },
        error: function (data) {
            console.log("Error: " + data);
        }

    });

};

handle_ajax(url1);

We can use Bootstrap Image carousel and SharePoint REST API with jQuery Ajax to achieve it, the following example for your reference. We can use Bootstrap Image carousel and SharePoint REST API with jQuery Ajax to achieve it, the following example for your reference.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.carouselCaption {
  background-color: #fee601;
  padding: 20px 20px 5px 20px;
  border: 4px solid #000;
  box-shadow: 5px 6px 0px #000;
}
</style>
<script type="text/javascript">
$(function() {
    var listName="funZone";
    GetImagesFromLibrary(listName);
});
function GetImagesFromLibrary(listName){
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listName+"')/items?$top=5&$orderby=Created desc";
    $.ajax({
        url: requestUri,
        method: "GET",
        async:false,
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            $.each(data.d.results,function(i,item){
                var cInnerHtml="";
                if(i==0){
                    $("#myCarousel .carousel-indicators").append('<li data-target="#myCarousel" data-slide-to="0" class="active"></li>');
                    cInnerHtml+='<div class="item active">';                                                            
                }else{                  
                    $("#myCarousel .carousel-indicators").append('<li data-target="#myCarousel" data-slide-to="'+i+'"></li>');
                    cInnerHtml+='<div class="item">';               
                }
                cInnerHtml+='<img src="'+item.Image.Url+'" alt="'+item.Title+'" style="width:100%;">';
                cInnerHtml+='<div class="carousel-caption" style="display:none;"><h3>'+item.Title+'</h3><p>'+item.Description+'</p></div></div>';
                $("#myCarousel .carousel-inner").append(cInnerHtml);                
            });
            $(".carousel-inner img").click(function(){
                $(".carouselCaption").html($(this).next().html());
            });
        },
        error: function (data) {
        }
    });
}
</script>
<div class="container">
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
        <!-- Indicators -->
        <ol class="carousel-indicators">
        </ol>
        <!-- Wrapper for slides -->
        <div class="carousel-inner">        
        </div>
        <!-- Left and right controls -->
        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
</div>
<section class="carouselCaption mb-1">   
</section>

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NaN尝试使用JavaScript从SharePoint列表中检索日期时 - NaN when trying to retrieve date from a SharePoint list using JavaScript 我正在尝试从JSON文件中检索数据,但是我无法从特定属性中检索信息 - I am trying to retrieve data from a JSON file, but I am having trouble retrieving information from a specific property 我正在尝试从 2 个数组中检索结果 - I am trying to retrieve result from 2 array 我正在尝试使用js将列表链接到共享网站,该列表是Utilities Contract,我想从该列表中提取特定列 - I am trying to link a list to a sharepoint website using js, the list is Utilities Contract and I want to bring back specific columns from that list 我正在尝试使用 nodejs 从 mongodb 集合中检索数据,但我必须请求两次才能获得正确的信息 - I am trying to retrieve data from mongodb collection using nodejs but i have to request it twice to get the correct information 我试图在单击按钮时停止两次显示同一对象的功能 - I am trying to stop my function from displaying the same object twice when clicking a button 我在尝试使用 Firebase JS SDK 从 Firestore 检索数据时遇到问题 - I am having an issue when trying to retrieve data from Firestore using the Firebase JS SDK 尝试从类中检索值时出现NAN错误? - I am getting NAN error when trying to retrieve a value from a class? 从共享点检索列表数据 - To retrieve list data from sharepoint 我正在尝试从 firebase 中的单个键中检索数据 - I am trying to retrieve data from a single key in firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM