[英]Bootstrap Popover Displaying the Same Contents
Has anyone worked with the bootstrap popover? 有人使用过引导程序弹出窗口吗? I am facing a little difficulty implementing it. 我在实施它时遇到了一些困难。
I am creating movie thumbnails dynamically, and on mouseenter event, I am using the popover to display the details of the image. 我正在动态创建电影缩略图,并且在发生mouseenter事件时,我正在使用弹出窗口显示图像的详细信息。 The problem is, the same details are displayed for all the images. 问题是,所有图像都显示相同的详细信息。
Here is some part of my code: 这是我的代码的一部分:
<script>
$(function () {
$(".get-movies").click(getEventHandler);
});
function getEventHandler() {
var name = $(".get-movie-name").val();
$.ajax({
url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=my_key&q=" + name + "&page_limit=5",
dataType: "jsonp",
success: function (response) {
$(".display-movie").empty();
var ul = $(".display-movie");
for (var i = 0; i < response.movies.length; i++) {
var img = $("<img>").attr("src", response.movies[i].posters.original)
.attr("id", i)
.attr("data-placement", "right")
.attr("class", "img-popover")
.on("mouseover", response, getPopOver)
.on("mouseout", hidePopOver)
.css({
width: 200,
height: 200,
margin: 20
});
var div = $("<div>")
.append(img)
$("<li>")
.append(div)
.appendTo(ul);
}
}
});
}
function getPopOver(info) {
console.log(info);
var image = '<img src = " ' +info.data.movies[info.target.id].posters.thumbnail+ ' " />';
$(".img-popover").popover({
title: info.data.movies[info.target.id].title,
content: image,
trigger: "hover",
html: true
})
}
function hidePopOver() {
console.log("Leaving here");
$(".img-popover").popover("hide");
}
</script>
I think your: 我认为您:
var name = $(".get-movie-name").val();
will return the first item in the collection of items that match that class. 将返回与该类匹配的项目集合中的第一项。
you might try: 您可以尝试:
var name = $('#' +this.id + ".get-movie-name").val();
but without seeing some of the html, I cannot be exact here. 但没有看到一些html,我在这里不准确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.