如何重新初始化Ajax调用后,猫头鹰旋转木马 [英] How to reinitialize Owl Carousel after ajax call

查看:661
本文介绍了如何重新初始化Ajax调用后,猫头鹰旋转木马的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想成功的Ajax调用后重新初始化猫头鹰旋转木马。 AJAX调用将改变数据,但认为应该留在same.I我有一个问题,即视图(转盘结构)不会reinitialize.Everything是罚款后,页面加载。

I am trying to reinitialize owl carousel after a successful ajax call. The ajax call will change the data but the view should stay the same.I am having an issue where the view (the carousel structure) will not reinitialize.Everything is fine upon page load.

使用1.3.3版本的即时通讯

im using version 1.3.3

$(document).ready(function() {
 $(".owl-carousel").owlCarousel({
   items : 3
 });
});

Ajax调用

Ajax call

$.ajax({
    type: 'get',
    url: '/public/index',
    dataType: 'script',
    data: data_send,
      success: function(data) {
       $(".owl-carousel").owlCarousel({
         items: 3
       });
      }
   });
}

我失去的东西,我需要做的。我已经看过这个问题GitHub的页面上,并尝试了建议,但都无济于事。

Am i missing something that i need to do. I have looked at this issue on the github page and tried the suggestions but to no avail.

pciated任何帮助AP $ P $

Any help appreciated

修改

从给出的建议我已经创建了这两个功能

from the advice given i have created these two functions

function owlCarousel() {
  var owl = $(".owl-carousel"); 
  //init carousel
  owl.owlCarousel();
    owl.data('owlCarousel').reinit({
     items : 3
    });
}

function destroyOwlCarousel() {
  var owl = $(".owl-carousel");
  //init carousel
  owl.owlCarousel();
    owl.data('owlCarousel').destroy();
  }
}

这似乎工作,但想知道如果这是正确的方式做这个?

It seems to work but wondering if this is the correct way to be doing this?

推荐答案

这应该帮助:

/*
 reinit() method reinitialize plugin 

 Syntax:
 owldata.reinit(newOptions)

 Yes! you can reinit plugin with new options. Old options
 will be overwritten if exist or added if new.

 You can easly add new content by ajax or change old options with reinit method.
 */

 $('.reinit').click(function(e){
 e.preventDefault()
 if(booleanValue === true){
  booleanValue = false;
  } else if(booleanValue === false){
  booleanValue = true;
}

owl.data('owlCarousel').reinit({
    singleItem : booleanValue
  });
})

这篇关于如何重新初始化Ajax调用后,猫头鹰旋转木马的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆