MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    how to pull new element added to an array?

    Scheduled Pinned Locked Moved Solved Troubleshooting
    57 Posts 4 Posters 19.4k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • justjim1220J Offline
      justjim1220 Module Developer
      last edited by

      OK, so I was able to modify the default newsfeed module to show an icon/image and got the description to marquee across the page.

      But, I want it to be able to use more than one feed.
      I can’t seem to get it to pull from the feeds array, I don’t get any errors from this, It just won’t show the image…

      Here is my current configuration that gives me the undefined image…

                       feeds: [
                              {
                                      icon: "NewYorkTimes.png",
                                      title: "New York Times",
      		       		url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
                              },
      			{
      				icon: "USAToday.png",
      				title: "USA Today",
      				url: "http://rssfeeds.usatoday.com/UsatodaycomNation-TopStories"
      			},
      			{
      				icon: "BBCWorldNews.png",
      				title: "BBC World News",
      				url: "https://www.bbc.com/news/world"
      			}
      		],
      
                  if (this.config.showMarquee && this.config.showIcon) {
                      var marquee = document.createElement("div");
                      marquee.className = "bright xlarge bold";
      
                      var icon = document.createElement("icon");
                      icon.innerHTML = "img class = image src=./modules/default/newsfeed/icons/" + this.newsItems[this.activeItem].icon;
                      wrapper.appendChild(icon);
                      
                      var txtDesc = document.createElement("marquee");
                      txtDesc.className = "bright xlarge bold";
                      txtDesc.innerHTML = moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + ":" + "  " + this.newsItems[this.activeItem].title; + "  ||  " + this.newsItems[this.activeItem].description + "    ||    ";
                      
                      wrapper.appendChild(txtDesc);
                  }
      

      Any ideas would be greatly appreciated!

      "Life's Too Short To Dance With Ugly People"
      Jim Hallock - 1995

      S 1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil @justjim1220
        last edited by sdetweil

        @justjim1220 said in how to pull new element added to an array?:

        this.newsItems

        what is that variable?
        this.config.feeds is the confiured data

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        justjim1220J 1 Reply Last reply Reply Quote 0
        • justjim1220J Offline
          justjim1220 Module Developer @sdetweil
          last edited by

          @sdetweil

          yeah, I was going by how the rest of the info (title, url, description, etc) is pulled from the feeds array, so thought it would be the same.

          "Life's Too Short To Dance With Ugly People"
          Jim Hallock - 1995

          1 Reply Last reply Reply Quote 0
          • S Away
            sdetweil
            last edited by

            can u show where newItems is set?

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            justjim1220J 3 Replies Last reply Reply Quote 0
            • justjim1220J Offline
              justjim1220 Module Developer @sdetweil
              last edited by

              @sdetweil

               start: function () {
                      Log.info("Starting module: " + this.name);
              
                      // Set locale.
                      moment.locale(config.language);
              
                      this.newsItems = [];
                      this.loaded = false;
                      this.activeItem = 0;
                      this.scrollPosition = 0;
              
                      this.registerFeeds();
              
              		"use strict";
              
                      this.isShowingDescription = this.config.showDescription;
                  },
              

              "Life's Too Short To Dance With Ugly People"
              Jim Hallock - 1995

              S 1 Reply Last reply Reply Quote 0
              • justjim1220J Offline
                justjim1220 Module Developer @sdetweil
                last edited by

                @sdetweil

                this is the default MM newsfeed, I am trying to modify it to show different things.

                "Life's Too Short To Dance With Ugly People"
                Jim Hallock - 1995

                1 Reply Last reply Reply Quote 0
                • justjim1220J Offline
                  justjim1220 Module Developer @sdetweil
                  last edited by

                  @sdetweil

                  My last modification was this…

                  https://forum.magicmirror.builders/assets/uploads/files/1539306174825-screenshot-140.png

                  https://forum.magicmirror.builders/assets/uploads/files/1539306174825-screenshot-141.png

                  https://forum.magicmirror.builders/assets/uploads/files/1539306174825-screenshot-142.png

                  "Life's Too Short To Dance With Ugly People"
                  Jim Hallock - 1995

                  1 Reply Last reply Reply Quote 0
                  • S Away
                    sdetweil @justjim1220
                    last edited by

                    @justjim1220 the problem is that the newsItems array is set from the rest api to pull the entries from the source. THAT data does NOT contain the icon you want to use.

                    your feed DEFINITION does , but not the feed response data…

                    so, can u tell from an item which ‘feeds’ entry caused this entry to be in the data? (ie, tell its source)… and can you search the feeds to locate the feed definition from any data in the item?

                    once u can do that, then u can use the feed entry icon

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    justjim1220J 2 Replies Last reply Reply Quote 0
                    • justjim1220J Offline
                      justjim1220 Module Developer @sdetweil
                      last edited by

                      @sdetweil

                      Not quite sure I am following you correctly…
                      Do you mean to pull the icon from the feeds source? the website?

                      "Life's Too Short To Dance With Ugly People"
                      Jim Hallock - 1995

                      1 Reply Last reply Reply Quote 0
                      • justjim1220J Offline
                        justjim1220 Module Developer @sdetweil
                        last edited by

                        @sdetweil

                        ok, so how would I be able to use the corresponding icons/images for the active feed showing if there isn’t any icon data in the rest API?

                        "Life's Too Short To Dance With Ugly People"
                        Jim Hallock - 1995

                        S 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 3
                        • 4
                        • 5
                        • 6
                        • 1 / 6
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Sam, technical setup by Karsten.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy