Javascript 初始化swiper滑块动态无法解释的行为
我必须动态创建swiper的实例。这些刷卡器具有动态填充的图像内容。我一整天都在与这个问题作斗争,因为我缺乏技能,无法让它发挥作用 没有javascript控制台错误,所以我假设有什么根本错误,但我不知道是什么 代码如下:Javascript 初始化swiper滑块动态无法解释的行为,javascript,dynamic,swiper,Javascript,Dynamic,Swiper,我必须动态创建swiper的实例。这些刷卡器具有动态填充的图像内容。我一整天都在与这个问题作斗争,因为我缺乏技能,无法让它发挥作用 没有javascript控制台错误,所以我假设有什么根本错误,但我不知道是什么 代码如下: <!-- The sliders are initiated very standard way, i skipped showing them. These are my paginations where I cannot get the pagination to
<!-- The sliders are initiated very standard way, i skipped showing them. These are my paginations where I cannot get the pagination to be rendered -->
<div class="secondary-0 swiper-pagination-clickable swiper-pagination-bullets"></div>
<div class="secondary-1 swiper-pagination-clickable swiper-pagination-bullets"></div>
<div class="secondary-2 swiper-pagination-clickable swiper-pagination-bullets"></div>
<script>
// I get lots of image data from php here
var imagearrays = <?php echo json_encode( $images_multiarray_js ); ?>;
// initialize variables for use in the loop.
var i;
var subNameArray = [];
var subSwiper = [];
// Loop through the imagearrays variable and initiate swipers.
for (i = 0; i < imagearrays.length; i++) {
subNameArray[i] = imagearrays[i].imagenames;
subSwiper = new Swiper('.subswiper-' + i, { // all my swiper-containers have extra class "subswiper-0" "subswiper-1" etc.
pagination: { // my main issue: I cannot get this pagination to render. WHY?
el: '.secondary-' + i, //my paginations have class like "secondary-0"
clickable: true,
renderBullet: function (index, className) {
return '<span class="' + className + '"><div class="pagination-ball"></div>' + subNameArray[index] + '</span>';
}
},
loop:true,
effect: 'fade',
clickable:true,
disableOnInteraction:false,
});
}
</script>
我试图在调试JS模式下逐行进行调试,但看起来控制台只是跳过了“new Swiper(…”行和其中的所有内容。同样,控制台中没有错误。如何感觉自己真的很愚蠢:
[
{"controllertype":false,"imagenames":["name1","name2"]},
{"controllertype":true,"imagenames":["name3","name4"]},
{"controllertype":false,"imagenames":["name5","name6"]}
]