Не удается прочитать находку undefined (fancybox) - PullRequest
0 голосов
/ 03 мая 2018

У меня есть вид с какой-то галереей

Вот код этого

 <div class="image_wrap">
  <a class="fancybox_43566 thumb_a" href="https://******.s3.amazonaws.com/hotelpictures/003/623/222/LON-91B-1.jpg?1387213390">
    <div class="image">
      <div class="resize-and-crop" style="width: 250px; height: 200px;"><img alt="Exterior" src="https://*******.s3.amazonaws.com/hotelpictures/003/623/222/LON-91B-1.jpg?1387213390" width="250" height="250" class="big_thumb" style="left: 0px; top: -25px;"></div>
    </div>
  </a>
  <div class="other_images">
      <div class="small_image">
        <a class="fancybox_43566" href="https://******.s3.amazonaws.com/hotelpictures/003/623/222/LON-91B-1.jpg?1387213390">
          <div class="resize-and-crop" style="width: 60px; height: 40px;"><img alt="Exterior" src="https://*****.s3.amazonaws.com/hotelpictures/003/623/222/LON-91B-1.jpg?1387213390" width="60" height="60" class="small_thumb_img" style="left: 0px; top: -10px;"></div>
        </a>
      </div>
      <div class="small_image">
        <a class="fancybox_43566" href="https://*******.s3.amazonaws.com/hotelpictures/003/623/225/LON-91B-2.jpg?1387213390">
          <div class="resize-and-crop" style="width: 60px; height: 40px;"><img alt="Lobby" src="https://******.s3.amazonaws.com/hotelpictures/003/623/225/LON-91B-2.jpg?1387213390" width="60" height="45" class="small_thumb_img" style="left: 0px; top: -3px;"></div>
        </a>
      </div>
      <div class="small_image">
        <a class="fancybox_43566" href="https://********.s3.amazonaws.com/hotelpictures/003/623/227/LON-91B-3.jpg?1387213390">
          <div class="resize-and-crop" style="width: 60px; height: 40px;"><img alt="Lobby" src="https://*******.s3.amazonaws.com/hotelpictures/003/623/227/LON-91B-3.jpg?1387213390" width="60" height="45" class="small_thumb_img" style="left: 0px; top: -3px;"></div>
        </a>
      </div>
      <div class="small_image">
        <a class="fancybox_43566" href="https://*******.s3.amazonaws.com/hotelpictures/003/623/230/LON-91B-4.jpg?1387213391">
          <div class="resize-and-crop" style="width: 60px; height: 40px;"><img alt="Lobby" src="https://*******.s3.amazonaws.com/hotelpictures/003/623/230/LON-91B-4.jpg?1387213391" width="60" height="45" class="small_thumb_img" style="left: 0px; top: -3px;"></div>
        </a>
      </div>
      <div class="small_image">
        <a class="fancybox_43566" href="https://*******.s3.amazonaws.com/hotelpictures/003/623/232/LON-91B-5.jpg?1387213391">
          <div class="resize-and-crop" style="width: 60px; height: 40px;"><img alt="Guest Room" src="https://******.s3.amazonaws.com/hotelpictures/003/623/232/LON-91B-5.jpg?1387213391" width="60" height="45" class="small_thumb_img" style="left: 0px; top: -3px;"></div>
        </a>
      </div>
  </div>
</div>

Мне нужно кликнуть на картинке, чтобы открыть галерею fancybox

Итак, в Rails View у меня есть этот код

<%= javascript_tag "$('.fancybox_#{hotel.id}').attr('rel', 'gallery').fancybox({ prevEffect : 'none', nextEffect : 'none', closeBtn : true, beforeShow : function() { var alt = this.element.find('img').attr('alt'); this.inner.find('img').attr('alt', alt); this.title = alt; }, helpers : { title : { type : 'inside' }} });" %>

Но когда я нажимаю на изображение, я получаю эту ошибку.

Невозможно прочитать свойство 'find' из undefined на Object.beforeShow (: 3: 164) в FancyBox.trigger (jquery.fancybox.js: 2669) в FancyBox.jumpTo (jquery.fancybox.js: 1058) в FancyBox.init (jquery.fancybox.js: 608) на новом FancyBox (jquery.fancybox.js: 514) в Object.open (jquery.fancybox.js: 2803) в HTMLAnchorElement._run (jquery.fancybox.js: 3048) в HTMLAnchorElement.dispatch (event.js: 340) в HTMLAnchorElement.elemData.handle (event.js: 148) на HTMLAnchorElement.fn .___ hb (honeybadger.js: 399)

В этой части тега скрипта this.element.find('img').attr('alt'); this.inner.find('img').attr('alt', alt); this.title = alt;

Где может быть моя проблема?

1 Ответ

0 голосов
/ 03 мая 2018

Так вот, ответ

Поскольку у меня нет элемента и внутреннего, код будет таким

  $('.fancybox_#{hotel.id}').attr('rel', 'gallery').fancybox({ prevEffect : 'none', nextEffect : 'none', closeBtn : true, beforeShow : function() { var alt = this.src; this.title = alt; }, helpers : { title : { type : 'inside' }} });

Я просто использую src в методе beforeShow, и он работает

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...