Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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 使用JSON和jQuery更新OwlCarousel';什么内容?_Javascript_Jquery_Html_Json - Fatal编程技术网

Javascript 使用JSON和jQuery更新OwlCarousel';什么内容?

Javascript 使用JSON和jQuery更新OwlCarousel';什么内容?,javascript,jquery,html,json,Javascript,Jquery,Html,Json,嗨,我是个笨蛋:(我正在处理这个单页项目,其中有一些产品库。这些产品存在于具有特定HTML ID的卡中。当我单击一张卡时,我希望我的jQuery脚本读取卡的HTML ID,并使用该字符串读取JSON文件,该文件包含所有库。这应该用img src标记填充我的库,该标记位于wlCarousel插件。我在一个图库中使用了它,但我不确定如何在其他图库中使用它。以下是我的jQuery: // waiting for the click on the .entry-card class $('.entry

嗨,我是个笨蛋:(我正在处理这个单页项目,其中有一些产品库。这些产品存在于具有特定HTML ID的卡中。当我单击一张卡时,我希望我的jQuery脚本读取卡的HTML ID,并使用该字符串读取JSON文件,该文件包含所有库。这应该用img src标记填充我的库,该标记位于wlCarousel插件。我在一个图库中使用了它,但我不确定如何在其他图库中使用它。以下是我的jQuery:

// waiting for the click on the .entry-card class

$('.entry-card').click(function() {

  // getting element id; i use this to read the JSON file
  var galleryNumber = $(this).prop('id');

  // firing up bootstrap modal
  $('#modal-gallery').modal();

  // firing up owl carousel inside #modal-gallery
  $('#modal-gallery-carousel').owlCarousel({
  singleItem : true,    
  lazyLoad : true,
  jsonPath : '../data/gallery-entries.json',
  jsonSuccess : customDataSuccess
});

// this is the part i don't get; it's straight out from the owlcarousel tutorial

function customDataSuccess(data) {
  var content = "";
  for (var i in data[galleryNumber]) {
    var img = data[galleryNumber][i].img;
    var alt = data[galleryNumber][i].alt;

    content += "<img src=\"" +img+ "\" alt=\"" +alt+ "\">"
    }
    $('#modal-gallery-carousel').html(content);
  }
});

// waiting for modal to finish closing

$('#modal-gallery').on('hidden.bs.modal', function() {
  $('#modal-gallery-carousel').html('');
  var owl = $('#modal-gallery-carousel').data('owlCarousel');
  owl.destroy();});
我尝试过重复相同的结构,但它不起作用;如果我这样做,我认为JSON是无效的。我应该怎么做

{

  // this corresponds to an id tag on the card

  "galeria1" : [
    {
        "img" : "images/buffet-ergo-1.jpg",
        "alt" : "Buffet Ergo"
    },
    {
        "img" : "images/buffet-ergo-1.jpg",
        "alt" : "Buffet Ergo"
    },
    {
        "img" : "images/buffet-ergo-1.jpg",
        "alt" : "Buffet Ergo"
    },
    {
        "img" : "images/buffet-ergo-1.jpg",
        "alt" : "Buffet Ergo"
    }
  ]
}