即使在javascript中保存了它的副本,数据也是空的(data is empty even after saving a copy of it in javascript)

编程入门 行业动态 更新时间:2024-10-26 06:36:48
即使在javascript中保存了它的副本,数据也是空的(data is empty even after saving a copy of it in javascript) 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空的。

这是this.getTwitterSearch :

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; }; var cacheData = JSON.stringify(data); this.getTwitterSearch(data, options); cache.setex(query, cfg.cache.news.twitter, cacheData, function(){ c.log('set cache', query, cacheData); });

If I comment out this.getTwitterSearch everything works fine. How can this be? I don't see how its possible that the function is making cacheData empty.

Here is this.getTwitterSearch:

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);遇到错误this.getTwitterItem(query, d); 它需要将query参数传递给它。 否则错误被抛到twit.search回调中,我把它作为数据读取,而不是错误。

I had an error in this.getTwitterItem(query, d); it need the query parameter to be passed to it. Otherwise the error was being thrown to the twit.search callback and I was reading it as data, not an error.

更多推荐

本文发布于:2023-08-01 10:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1357918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中保   副本   存了   数据   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!