具有动态长度的循环的Javascript

具有动态长度的循环的Javascript,javascript,loops,conditional-statements,Javascript,Loops,Conditional Statements,我有一段代码来拉推特提要,它工作得很好,但有时帖子不包含图片。我想获得设置。计算要显示的帖子数量,但我得到的较少,因为缺少图像。 我怎样才能获得原始数量的帖子 $.getJSON(settings.apiPath, { username: settings.username, list: settings.list, hashtag: settings.hashtag, count: settings.count, exclude_replies: settings.hideReplies },

我有一段代码来拉推特提要,它工作得很好,但有时帖子不包含图片。我想获得
设置。计算要显示的帖子数量,但我得到的较少,因为缺少图像。
我怎样才能获得原始数量的帖子

$.getJSON(settings.apiPath, { username: settings.username, list: settings.list, hashtag: settings.hashtag, count: settings.count, exclude_replies: settings.hideReplies }, function (twt) {
        that.find('span').fadeOut('fast', function () {
            that.html('<ul></ul>');

            for (var i = 0; i < settings.count; i++) {
                var tweet = false;
                if (twt[i]) {
                    tweet = twt[i];
                } else if (twt.statuses !== undefined && twt.statuses[i]) {
                    tweet = twt.statuses[i];
                } else {
                    break;
                }

                var temp_data = {
                    user_name: tweet.user.name,
                    date: dating(tweet.created_at),
                    tweet: (tweet.retweeted) ? linking('RT @' + tweet.user.screen_name + ': ' + tweet.retweeted_status.text) : linking(tweet.text),
                    avatar: '<img src="' + tweet.user.profile_image_url + '" />',
                    url: 'http://twitter.com/' + tweet.user.screen_name + '/status/' + tweet.id_str,
                    retweeted: tweet.retweeted,
                    screen_name: linking('@' + tweet.user.screen_name),
                    image: (tweet.entities.media) ? "<img src='" + tweet.entities.media[0].media_url + "' />" : false
                };

                that.find('ul').append('<li>' + templating(temp_data) + '</li>');
            }

            if (typeof callback === 'function') { callback(); }
        });
    });
$.getJSON(settings.apiPath,{username:settings.username,list:settings.list,hashtag:settings.hashtag,count:settings.count,exclude_repress:settings.hideReplies},函数(twt){
that.find('span')。fadeOut('fast',function(){
html(“
    ”); 对于(变量i=0;i'+模板(temp_数据)+''); } if(typeof callback==='function'){callback();} }); });

    我认为某个地方应该有这样一个if语句:
    typeof twt[I].entities.media!='未定义“

    您是否尝试使用twitter API???是的,我尝试过。这是一种定制方法。我认为不管是Twitter API还是其他什么,我只是想找到一种方法来排除没有图片的帖子。我在想,也许我可以在循环中增加/减少它。你能提供一个可以重现问题的工作示例(例如,working examle或git repo)和发生问题的模拟数据吗???