Вопрос

I'm working with Google Feed API for RSS feeds and need to add the values of the fetched RSS feed item array to create another array (that is used to create a javascript bar graph of the data).

The array would be this:

arrayOfData = new Array(
     [THE_FEED_ITEM_CONTENT, THE_FEED_ITEM_TITLE,'#cccccc']
);

I'm using jqBarGraph for the graph.

For context, this is the part of the code that displays the feed and subsequently grabs that values that I need to create the array mentioned. It is currently a part of creating a table of the of the data coming through the feed:

function displayfeed(result){

if (!result.error){
var thefeeds=result.feed.entries
for (var i=0; i<thefeeds.length; i++) {
xlabel+="<td>" +  thefeeds[i].title + "</td>";
xdata+="<td>" + thefeeds[i].content + "</td>";
}
rssoutput+=xlabel + "</tr></thead>" + xdata + "</tr></tbody></table>"
feedcontainer.innerHTML=rssoutput
}
else
alert("Error fetching feeds!")
}

window.onload=function(){
rssfeedsetup()
}

Here is an example of the array used to create the javascript graphs (with absolute values):

arrayOfData = new Array(
     [10.3,'Jan','#cccccc'],
     [15.2,'Feb','#cccccc'],
     [13.1,'Mar','#cccccc'],
);

Now, I need that array to be filled with:

arrayOfData = new Array(
     [thefeeds[i].content, thefeeds[i].title,'#cccccc']
);

The idea, of course, is to fill the array above with each item on the RSS feed. One line filled out with thefeeds[i].content & [thefeeds[i].title and so and so forth.

Thank you in advance for any advice.

Это было полезно?

Решение

var thefeeds=result.feed.entries;
var arrayOfData = new Array();
for (var i=0; i<thefeeds.length; i++) {
  arrayOfData.push([thefeeds[i].content,thefeeds[i].title,'#cccccc']) 
}

Другие советы

Loop through the array. This is not combining as it is usually defined (done with Array.concat in javascript)

var arrayOfData = new Array();
for(var feed in thefeeds) {
    arrayOfData.push(feed.content, feed.title, '#cccccc');
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top