Read the statement by Michael Teeuw here.
how to pull new element added to an array?
-
@justjim1220 said in how to pull new element added to an array?:
var image = item.image || item.logo || item.img || item.svg || “”;
that looks good, except as you note, these are optional in the response (item) data.
do you want to use the configured url for the feed if not present?
var image = item.image || item.logo || item.img || item.svg || xxxx.yyy.icon || "";
the feed definition is passed into the fetcher function. except that routine could have ended seconds ago, when the parser.on(item) method is called (by the callback)…
so, what should xxxx.yyy be? can’t use the parm feed directly, as the routine could have exited already…
so, javascript gives you the ability to bind (connect) a variable with a routine when it is called asyncronously…
when u bind the variable, it will be accessible in the context of the function, context = this,
so, on the close brace of the function defined on the .on(), add the .bind() clause.
inside the bind clause, you specify the name of the variable INSIDE the function, and connect it to the variable at the time the .on() definition is called… (ie ‘feed’)…
so,
}.bind({feed_var_in_function:feed})
then when the function is called, you can get access to the variable using ‘this’…
this.feed_var_in_function.icon, would be the icon defined for THIS feed
therefore the stmt above would be
var image = item.image || item.logo || item.img || item.svg || this.feed_var_in_function.icon || "";
this says, use any of the optional images in the feed item, if present,
else use the user defined feed icon,
else nothing if not defined… -
ok, so do I need to add it like this:
parser.on("image", function(image){}) var title = image.title; var image = image.image || image.logo || image.img || image.svg || this.feed_var_in_function.icon || ""; var url = image.url || image.link || "";
Or, like this:
parser.on("image", function(image){}) var title = image.title; var image = item.image || item.logo || item.img || item.svg || this.feed_var_in_function.icon || ""; var url = image.url || image.link || "";
-
Why are making this so hard?
-
GOD, I WISH I KNEW!!!
-
@sdetweil, @cowboysdude, @Sean
I created a repository, hopefully it will make it easier for you to help.
https://github.com/justjim1220/MMM-NewsFeedTicker
ALL help is MUCH APPRECIATED!!!
I gotta learn this stuff one way or another!
:smiling_face_with_sunglasses:
-
@justjim1220 I am trying to test my changes, but the module getDom() method is never called…
changed the module name in module.js to match the file name and config module name.
loads with no errors, shows loading the module js and registering the module…
-
What is the possibility of using and array of sorts?
place the logos in a pics folder, call them according to the newsItem[activeItem].title, Ive seen some examples, and tried it a few different ways, but not sure if I am missing something as I can’t get it to work.
recent example tried:
feeds…{ title: "New York Times: ", url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml" }, { title: "Wall St. Journal: ", url: "http://www.wsj.com/xml/rss/3_7085.xml" }, { title: "USA Today: ", url: "http://rssfeeds.usatoday.com/UsatodaycomNation-TopStories" }, { title: "BBC World News: ", url: "http://feeds.bbci.co.uk/news/world/rss.xml#" }
Array…
iconArray: { "USAToday": "USA Today: ", "NewYorkTimes": "New York Times: ", "WallStJournal": "Wall St. Journal: ", "BBCWorldNews": "BBC World News: " }
Added this to start function…
this.logo = {};
sample code…
var logo = this.logo; if (this.config.showDescription) { var description = document.createElement("div"); //description.setAttribute("style", "padding-top: 25px"); description.className = "bright xlarge bold" + (!this.config.wrapDescription ? " no-wrap" : ""); var txtDesc = this.newsItems[this.activeItem].description; description.innerHTML = "<img class = image src=./modules/default/newsfeed/pics/" + logo.icon + ".png height=150px valign=middle>" + "<marquee scrollamount=20 scrolldelay=0 left=500px>" + "<font color=yellow>" + moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + " : " + "</font>" + this.newsItems[this.activeItem].title + " || " + txtDesc + "</marquee>"; wrapper.appendChild(description); }
Any chance this could work easier if I had it coded correctly?
Seems Like I should be declaring the
newsItem[activeItem].title
to equal the icon/logo in some fashion…
-
@justjim1220 no, not really…
-
ok, just a thought, seen it with a few other modules. Thanks!
-
@justjim1220 any idea why the newsticker doesn’t work at all?
u don’t have a package.json, so the install instructions for npm install is not needed…