0
我有這種格式的圖片數組:獲取顯示圖像索引
[#<BookPhotoUploader:0x00000042103ec0
@file=
#<CarrierWave::SanitizedFile:0x000000421013e0
@content_type=nil,
@file=
"/.../.../.../public/uploads/book/pictures/1/first.jpg",
@original_filename=nil>,
@model=
#<Book:0x00000049fab1f0
id: 1,
...
pictures: ["first.jpg", "second.jpg"]>,
@mounted_as=:pictures,
@storage=
#<CarrierWave::Storage::File:0x00000046803dw0
@uploader=#<BookPhotoUploader:0x00000042103ec0 ...>>,
@versions={}>,
...]
當我顯示的圖片,它看起來像:
<img id="book_picture" src="/uploads/book/pictures/1/first.jpg" alt="First">
如何在找到特定的圖片索引數組如果我試圖獲取有關使用jQuery顯示的圖片的信息?
究竟是什麼你想實現什麼?你顯示數組中的一些圖像,並希望向他們保存一些關於圖像在數組中的索引的信息?您可以使用例如'each_with_index'循環遍歷所有圖像及其索引,並將索引存儲在圖像標籤的'data'屬性中。 – BoraMa