亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何創建盡可能多的動態El,就像我們從PHP收到的那樣

如何創建盡可能多的動態El,就像我們從PHP收到的那樣

PHP
慕尼黑8549860 2022-09-17 17:27:35
在主頁上有圖庫,點擊一個圖像需要打開光畫廊幻燈片與在ftp目錄上找到的圖像,與畫廊名稱點擊主頁上。PHP用于查找圖像并計數:<?phpheader("Content-Type: application/json");$dirname = $_POST["galleryName"];$imgGallery = glob("../gallery/" . $dirname . "/".$dirname."_*.*");$thumbGallery = glob("../gallery/" . $dirname . "/thumb_*.*");$countImages = count($imgGallery);echo json_encode(array("imgNormal" => $imgGallery, "imgThumb" => $thumbGallery, "imgCount" => $countImages));?>斷續器:$('.info').click(function() {    var galleryName = $(this).closest('.imgGallery').find('img.img-thumbnail').attr('name');    $.ajax({        url: "gallery/imgFinder.php",        dataType: "json",        type: "post",        data: {            galleryName: galleryName        },        success: function(xhr) {            if (xhr.imgCount != 0) {                console.log(xhr.imgNormal);                console.log(xhr.imgThumb);                console.log(xhr.imgCount);                for (var i = 1; i <= xhr.imgCount; i++) {                    $(this).lightGallery({                        dynamic: true,                        dynamicEl: [{ //We need to create as much as we received w "xhr.imgCount"                                        "src": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg",                                        "thumb": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg"                        }]                    })                    return;                }            } else {                console.log('Gallery \'' + galleryName + '\' has no images');                return;            }        },        error: function(xhr) {            console.error("Some error found");        }    });});我們需要使用圖像/拇指變量創建盡可能多的動態El,就像我們收到 xhr.imgCount 一樣要獲得類似這樣的東西:dynamicEl: [{    "src": '...',    'thumb': '...'}, {    'src': '...',    'thumb': '...'}, {    'src': '...',    'thumb': '...'}, {    'src': '...',    'thumb': '...'}]
查看完整描述

1 回答

?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

在你的JS代碼中,你需要更新如下內容:


if (xhr.imgCount != 0) {

        console.log(xhr.imgNormal);

        console.log(xhr.imgThumb);

        console.log(xhr.imgCount);

        var dynamicEls = [];

        for (var i = 0; i <= xhr.imgCount; i++) {


              dynamicEls[i] = { 

                    "src": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg",

                    "thumb": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg"

                };

        }

        dynamicEls.pop(); //For remove unrealized last url/data

        $(this).lightGallery({

           dynamic: true,

           dynamicEl: dynamicEls

        });

    }

因此,我正在使用和溫度變量,并在循環后將其填充在正確的位置。dynamicEls


查看完整回答
反對 回復 2022-09-17
  • 1 回答
  • 0 關注
  • 137 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號