var cacheData = JSON.stringify(data);

this.getTwitterSearch(data, options);

cache.setex(query, cfg.cache.news.twitter, cacheData, function(){
    c.log('set cache', query, cacheData);
});

如果我发表评论,一切正常。怎么会这样?我不明白这个函数怎么可能把this.getTwitterSearch变成空的。
这里是cacheData
News.prototype.getTwitterSearch = function getTwitterSearch(data, options){
    var statuses = data.statuses
        , items = [];

    c.log('statuses', statuses);

    _.each(statuses, function(d){
        var item = this.getTwitterItem(query, d);

        if ( item ) {
            items.push(item);
        }
    }.bind(this));

    //recent items since last poll
    if ( options.since_id ) {
        if ( items.length ) {
            this.sock.emit('twitter:new', { items: items });
        }
    } else {
        //initial payload
        c.log('twitter:items', items.length);
        if ( items.length ) {
            this.sock.emit('twitter:items', { items: items });
        }
    }

    c.log('items', items.length);

    //TODO set cache items

    //save the last id to use when fetching new items on next poll.
    this.lastId = items.length && items[0].id || this.lastId;
};

最佳答案

我在this.getTwitterItem(query, d);中出错,需要将query参数传递给它。否则,错误将被抛出到twit.search回调,我将其作为数据读取,而不是错误。

关于javascript - 即使在javascript中保存了它的副本,数据也是空的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20823092/

10-15 09:49
查看更多