如何用新的项目替换/重建_ids
项?
在许多情况下,就像从数据库中获取新数据一样,您可以在轮播中添加新数据,但在此示例中,我尝试使用新数据替换所有项目。
from elasticsearch import Elasticsearch
es = Elasticsearch()
request_body = {
"query": {
"ids": {
"values": ['a','b','c','d','e','f']
}
}
}
es.delete_by_query(index=es_index, body=request_body)
owl carousel
答案 0 :(得分:7)
根据Owl Carousel 2 documentation,您可以使用replace.owl.carousel
事件。
输入:triggerable
参数:data
删除当前内容并添加参数中传递的新内容。
首先,您需要使用replace
触发器,然后使用refresh
触发器附加新数据。请勿使用destroy
或re-initialize
示例1 / 更新/替换
$('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
nav: true
});
$('#reb').click(function() {
var html = '<div class="owl-item"><h4>1-2</h4></div><div class="item"><h4>2-2</h4></div><div class="item"><h4>3-2</h4></div><div class="item"><h4>4-2</h4></div><div class="item"><h4>2-2</h4></div>';
$('.owl-carousel').trigger('replace.owl.carousel', html).trigger('refresh.owl.carousel');
});
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
.btn-success {
color: #fff;
background-color: #5cb85c;
border-color: #4cae4c;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.default.min.css" />
<div class="owl-carousel owl-theme">
<div class="item">
<h4>Old 1-1</h4>
</div>
<div class="item">
<h4>Old 2-1</h4>
</div>
<div class="item">
<h4>Old 3-1</h4>
</div>
<div class="item">
<h4>Old 4-1</h4>
</div>
</div>
<a id="reb" class="btn btn-success">Rebuild</a>
示例2 / 更新/添加
$('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
nav: true
});
$('#reb').click(function() {
var html = '<h4>New item</h4>';
$('.owl-carousel').trigger('add.owl.carousel', html).trigger('refresh.owl.carousel');
});
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
.btn-success {
color: #fff;
background-color: #5cb85c;
border-color: #4cae4c;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.default.min.css" />
<div class="owl-carousel owl-theme">
<div class="item">
<h4>Old 1-1</h4>
</div>
<div class="item">
<h4>Old 2-1</h4>
</div>
<div class="item">
<h4>Old 3-1</h4>
</div>
<div class="item">
<h4>Old 4-1</h4>
</div>
</div>
<a id="reb" class="btn btn-success">Add</a>