Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 初始化swiper滑块动态无法解释的行为_Javascript_Dynamic_Swiper - Fatal编程技术网

Javascript 初始化swiper滑块动态无法解释的行为

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

我必须动态创建swiper的实例。这些刷卡器具有动态填充的图像内容。我一整天都在与这个问题作斗争,因为我缺乏技能,无法让它发挥作用

没有javascript控制台错误,所以我假设有什么根本错误,但我不知道是什么

代码如下:

<!-- 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(…”行和其中的所有内容。同样,控制台中没有错误。

如何感觉自己真的很愚蠢:

  • 花半天时间找出代码不起作用的原因
  • 一时兴起,检查您的swiper选择器类是否附加到正确的html元素,并意识到它不是
  • 去哭吧
  • 对不起,伙计们,这个问题没用。在d'oh修复中,一切都按预期进行

    [
      {"controllertype":false,"imagenames":["name1","name2"]},
      {"controllertype":true,"imagenames":["name3","name4"]},
      {"controllertype":false,"imagenames":["name5","name6"]}
    ]