0

I am modifying my previous question since I feel this problem is closely related to putting an entry in map from ajax call. There is nothing wrong with Map.

EDIT :-

I am populating a map of feeds in following ways where key represent url and value represent feeds;

channelMap.each(function(key,url,n){
    loadFeedFor(url,10);
    console.debug(feedMap);
});
:
function loadFeedFor(url,maxposts){
     var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+url;
     if(maxposts != null) gurl += "&num="+maxposts;
      $.getJSON(gurl, function(){})
     .done(function(data){
         feeds = data.responseData.feed;
         feedMap.put(url,feeds);
      });
 }

But it is not working. I guess I would have to use Deffered for this problem but have no idea how.

I am using map from this answer.

I tried doing same thing in another way where I am not using map. I am calling following function with different 3 rss feeds url;

function rssfeedsetup(feedId,feedurl,feedlimit){
    var feedpointer=new google.feeds.Feed(feedurl); //Google Feed API method
    feedpointer.setNumEntries(feedlimit); //Google Feed API method
    feedpointer.load(function(response){
        console.log(response.feed);
        return setTimeout(displayFeed(response.feed,feedId), 3000);
    }); //Google Feed API method
}

console prints all feeds properly (25 entries). But feeds actually appear on page are always less. Even delay is not helping me.

Community
  • 1
  • 1
Amit Kumar Gupta
  • 7,193
  • 12
  • 64
  • 90
  • 1
    Are you waiting for `$.jGFeed` to complete before trying to use the map? – James M May 18 '13 at 12:30
  • nope. And I guess this is only the problem. How can I do this? – Amit Kumar Gupta May 18 '13 at 12:38
  • Is it possibly a variable scope issue? What does console.debug(some key) and console.debug(channelMap) print if called in the anonymous function? – miah May 18 '13 at 12:42
  • they gets printed properly but same as "in calls" gets printed, after "out of call". console.debug(channelMap) prints `Map {keys: Array[i], data: Object, put: function, get: function, remove: function…};` where i is incremented value. – Amit Kumar Gupta May 18 '13 at 12:45
  • I have resolved the issue of executing next function before finishing the call of `$.jGFeed`. Still problem persist :( – Amit Kumar Gupta May 18 '13 at 13:26
  • Can someKey be null? In the provided code of put function the array is not filled if it is null – Irvin Dominin May 18 '13 at 13:50
  • WTH is that code supposed to do? Currently you're returning a Deferred which resolves with an empty string after a random time (up to 4s). The `$.jGFeed` and the `channelMap` are completely unrelated – Bergi May 18 '13 at 14:34
  • Why don't you use [this answer](http://stackoverflow.com/a/4247008/1048572) for the map? – Bergi May 18 '13 at 14:36

0 Answers0