【问题标题】:instagram api jquery not displaying pictures correctlyinstagram api jquery 无法正确显示图片
【发布时间】:2015-08-20 22:25:42
【问题描述】:

我对 Jquery 和 Javascript 还是很陌生,使用此处提供的 API 时遇到了一些问题

https://github.com/potomak/jquery-instagram

我正在尝试循环并抓取多批图片并将它们全部显示到一个 div 中。这是我当前代码的一部分:

$('#morebutton').click(function(){
var numtimes = 3;
console.log("main fun  " + numtimes)
GetMorePictures(numtimes);
});

function GetMorePictures(numtimes) {
    //$("#pictures").html($("#pictures").html() + "<h1>Page " + pagenum++ + "</h1>")
    if (numtimes == 0) {
        return
    }
    console.log("inside fun  " + numtimes)
  $('.instagram2').instagram({
    search: {
    lat: lat,
    lng: lng,
    distance: document.getElementById('Distance').value,
    max_timestamp: ( (document.getElementById("Timing").selectedIndex == 1)? null:nexttime),
    min_timestamp: ( (document.getElementById("Timing").selectedIndex == 1)? prevtime:null)
  },
    count : 100,
    clientId: '7d428aff533f40e1b3d5f919882576d2'
  });

}

$('.instagram2').on('willLoadInstagram', function(event, options) {
    console.log(options);
});

$('.instagram2').on('didLoadInstagram', function(event, response) {
    console.log("just loaded")
    console.log(response)
    //console.log("1")
    prevtime = response.data[0].created_time
    nexttime = response.data[response.data.length - 1].created_time
    var inputTag = document.getElementById("Tag");
    if (inputTag && inputTag.value) {
        for (i = 0; i < response.data.length; i++) {
            if ( $.inArray(inputTag.value, response.data[i].tags) > -1 ) {
                if(i != 0){
                    $("#pictures").html($("#pictures").html() + "<a href='"+response.data[i].link+"' target='_blank'> <img src='"+response.data[i].images.thumbnail.url+"' height=150 width=150 /> </a>")
                }
            }   
        }
    }else {
        for (i = 0; i < response.data.length; i++) {
            if(i != 0){
                $("#pictures").html($("#pictures").html() + "<a href='"+response.data[i].link+"' target='_blank'> <img src='"+response.data[i].images.thumbnail.url+"' height=150 width=150 /> </a>")
            }
        }
    }
    //console.log("2")
    if( $('#pictures').is(':empty') ) {$("#pictures").html($("#pictures").html() + "No Result, Try another search or load more results")}
    searched = true;
    console.log("about to recur");
    GetMorePictures(numtimes - 1);
});

我尝试在 GetMorePictures 函数的内部和外部移动一些东西,但它不能正常工作。如果它们在函数中,则它们会显示多次,如果它们在函数之外,则根本不显示。

非常感谢任何帮助。

【问题讨论】:

    标签: javascript jquery instagram-api


    【解决方案1】:

    对GetMorePictures(numtimes - 1) 的调用无法正常工作,因为您引用的numtimes 在didLoadInstagram 事件回调的上下文中未定义。为了快速而肮脏的修复,请尝试将该变量的定义移到 onclick 回调之外。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 2014-11-05
      相关资源
      最近更新 更多