0

Strange behavior passing Playlist.ID

Hello All,

I'm running into some Strange behavior passing Playlist.ID to the player view. Please note I'm not a native JavaScript coder so I may be missing somthting.

Basicly I modified the Playlist array to have a category attribute. Then in one of my views I'm iterating through the playlist and creating a button for each entry that matches the category attribute for that view. However, for some reason no matter what button I select only the playlist id of the last button that is created gets passed to the player view.

Below is the code from the view.


var VideosView = new KONtx.Class({
  ClassName: 'VideosView',

  Extends: KONtx.system.SidebarView,

  createView: function() {

        var backButton = new KONtx.control.BackButton({
            label: 'Watch Fishing Show Highlights',
        }).appendTo(this);

        var vOffsetValue = backButton.outerHeight;
        var playlists = KONtx.messages.fetch("playlists");

        if(playlists instanceof Array) {
            log("We have our data, so we are good to go.");
            for each(var playlist in playlists) {
                log(playlist.Title);
                log(playlist.entryType);
                if(playlist.entryType == 'Shows') {
                    var play_video_id = new KONtx.control.TextButton({
                        id: 'play_video_id_' + playlist.ID,
                        label: playlist.Title,
                        disabled: false,
                        styles: {
                            vOffset: vOffsetValue
                        },
                        events: {
                            onSelect: function(event) {
                                KONtx.application.loadView('view-Player', { PlaylistID: playlist.ID });
                                }
                        }
                    }).appendTo(this);
                    vOffsetValue = vOffsetValue + 35;
                }
            }
            return;
        };
  },

});
 

by
7 Replies
  • Anyone out there in Yahoo land??
    0
  • Hey,....I saw your posts in the other forums.  I can't say anything definite about the popularity of the Yahoo Connected platform.  Certainly support is dificult to come by.  Devici and some others used to offer some free code on their site but it's since become paywalled.  My client has requested develpoment on this platform solely in the name of market permeation; despite Yahoo's boasts of a install base in the millions, they are not expecting much in terms of users.

    Your issue is happening because you are referencing the variable playlist.ID.  This line:
    for each(var playlist in playlists) {
    redefines the variable playlist as each item in the playlists array.  After the loop has finished, the variable playlist remains as the last array item.  Thus, subsequent calls to the variable playlist will always be tied to the last item in the array.

    What you need to do is alter your onSelect event.  I recommend something like this:
    onSelect: function(event) {
         var pid=this.id.split('_').pop();
         KONtx.application.loadView('view-Player', { PlaylistID: pid });
    }

    When you use the this keyword in an event like onSelect, onBlur, etc. it references that control.  Since you had the foresight to include each playlists ID in an underscore delimited variable, you can easily isolate the desired id by using the Javascript functions split() and pop()


    QUOTE(Daniel @ 9 Nov 2011 4:49 PM)
    Anyone out there in Yahoo land??
    0
  • Buddy,

    Thanks for the reply...  I was hoping my comments would warrant some undue attention. ;-)

    I attepted your fix and I am getting: TypeError: this.id is undefined (videos.js: Line 34)

    The varable/object scope is not working the way I would expect. Not sure how to persist things. Kind of like its passing by reference and not the current value of the varable when the button is created. Mind you the labels work but the event call is not picking up the current state.

    As far as the platform I think yahoo got off to a good start, but they need to do more to support what they have. Otherwise all the other connected tv options will take away their first mover advantage. i.e. Apple, Google, etc..

    -Daniel

    QUOTE(buddy @ 9 Nov 2011 7:20 PM)
    Hey,....I saw your posts in the other forums.  I can't say anything definite about the popularity of the Yahoo Connected platform.  Certainly support is dificult to come by.  Devici and some others used to offer some free code on their site but it's since become paywalled.  My client has requested develpoment on this platform solely in the name of market permeation; despite Yahoo's boasts of a install base in the millions, they are not expecting much in terms of users.

    Your issue is happening because you are referencing the variable playlist.ID.  This line:
    for each(var playlist in playlists) {
    redefines the variable playlist as each item in the playlists array.  After the loop has finished, the variable playlist remains as the last array item.  Thus, subsequent calls to the variable playlist will always be tied to the last item in the array.

    What you need to do is alter your onSelect event.  I recommend something like this:
    onSelect: function(event) {
         var pid=this.id.split('_').pop();
         KONtx.application.loadView('view-Player', { PlaylistID: pid });
    }

    When you use the this keyword in an event like onSelect, onBlur, etc. it references that control.  Since you had the foresight to include each playlists ID in an underscore delimited variable, you can easily isolate the desired id by using the Javascript functions split() and pop()


    QUOTE(Daniel @ 9 Nov 2011 4:49 PM)
    Anyone out there in Yahoo land??
    0
  • oops, youre right....I'll have to make sure to check my code before I post it :p

    What you should actually do is attach an extra variable to your TextButton object affter you attach it.  You can then reference that property in the onSelect event.

    Here are the relevant bits of code:

    onSelect: function(event) {
        KONtx.application.loadView('view-Player', { PlaylistID: this.pid });  //Reference your added variable here

     }).appendTo(this);
    play_video_id.pid=playlist.ID  //ADD THIS LINE!
    vOffsetValue = vOffsetValue + 35;

    Let me know if this doesnt work

    QUOTE(Daniel @ 10 Nov 2011 4:42 PM)
    Buddy,

    Thanks for the reply...  I was hoping my comments would warrant some undue attention. ;-)

    I attepted your fix and I am getting: TypeError: this.id is undefined (videos.js: Line 34)

    The varable/object scope is not working the way I would expect. Not sure how to persist things. Kind of like its passing by reference and not the current value of the varable when the button is created. Mind you the labels work but the event call is not picking up the current state.

    As far as the platform I think yahoo got off to a good start, but they need to do more to support what they have. Otherwise all the other connected tv options will take away their first mover advantage. i.e. Apple, Google, etc..

    -Daniel

    QUOTE(buddy @ 9 Nov 2011 7:20 PM)
    Hey,....I saw your posts in the other forums.  I can't say anything definite about the popularity of the Yahoo Connected platform.  Certainly support is dificult to come by.  Devici and some others used to offer some free code on their site but it's since become paywalled.  My client has requested develpoment on this platform solely in the name of market permeation; despite Yahoo's boasts of a install base in the millions, they are not expecting much in terms of users.

    Your issue is happening because you are referencing the variable playlist.ID.  This line:
    for each(var playlist in playlists) {
    redefines the variable playlist as each item in the playlists array.  After the loop has finished, the variable playlist remains as the last array item.  Thus, subsequent calls to the variable playlist will always be tied to the last item in the array.

    What you need to do is alter your onSelect event.  I recommend something like this:
    onSelect: function(event) {
         var pid=this.id.split('_').pop();
         KONtx.application.loadView('view-Player', { PlaylistID: pid });
    }

    When you use the this keyword in an event like onSelect, onBlur, etc. it references that control.  Since you had the foresight to include each playlists ID in an underscore delimited variable, you can easily isolate the desired id by using the Javascript functions split() and pop()


    QUOTE(Daniel @ 9 Nov 2011 4:49 PM)
    Anyone out there in Yahoo land??
    0
  • Apologize for the delay in reply on behalf of Yahoo. We are a small team here, doing everything, including development/support and replying in forums. So, sometimes you may experience such delays. But we want to assure you that we are fully committed to this product and intend to continue innovating and maintaining our leadership in this market. Let me know if you still have any doubts after going through buddy's solution.

    Thanks,
    Vivek
    0
  • Hi Vivek,

    Thanks for the note! I think your team is doing a fantastic job. :-)

    However, I think you just validated my initial point. i.e. you are a small team doing everything with limited resources. I'm willing to bet, the management at both Apple and Google have committed more cash and talent to their current connected tv offerings. Mind you small teams can make a big inpact, but they have to scale up at some point to address the market.

    I personally think that the television internet convergence and yahoo connected tv in particular are good strategic bets for yahoo in the long term. From the outside looking in though it looks like your board/management should consider investing the additional resources it deserves. Especially, Given the competition is now making big bets in the same space. That all I'm saying.

    Anyways thanks for the help. Looking forward to getting our App approved and launched on the Yahoo Connected TV Platform.

    -Daniel

    QUOTE(Vivek Jani @ 10 Nov 2011 9:40 PM)
    Apologize for the delay in reply on behalf of Yahoo. We are a small team here, doing everything, including development/support and replying in forums. So, sometimes you may experience such delays. But we want to assure you that we are fully committed to this product and intend to continue innovating and maintaining our leadership in this market. Let me know if you still have any doubts after going through buddy's solution.

    Thanks,
    Vivek
    0
  • Buddy,

    That did it! Thank you! I owe you a cold one! :-)

    -Daniel


    QUOTE(buddy @ 10 Nov 2011 7:46 PM)
    oops, youre right....I'll have to make sure to check my code before I post it :p

    What you should actually do is attach an extra variable to your TextButton object affter you attach it.  You can then reference that property in the onSelect event.

    Here are the relevant bits of code:

    onSelect: function(event) {
        KONtx.application.loadView('view-Player', { PlaylistID: this.pid });  //Reference your added variable here

     }).appendTo(this);
    play_video_id.pid=playlist.ID  //ADD THIS LINE!
    vOffsetValue = vOffsetValue + 35;

    Let me know if this doesnt work

    QUOTE(Daniel @ 10 Nov 2011 4:42 PM)
    Buddy,

    Thanks for the reply...  I was hoping my comments would warrant some undue attention. ;-)

    I attepted your fix and I am getting: TypeError: this.id is undefined (videos.js: Line 34)

    The varable/object scope is not working the way I would expect. Not sure how to persist things. Kind of like its passing by reference and not the current value of the varable when the button is created. Mind you the labels work but the event call is not picking up the current state.

    As far as the platform I think yahoo got off to a good start, but they need to do more to support what they have. Otherwise all the other connected tv options will take away their first mover advantage. i.e. Apple, Google, etc..

    -Daniel

    QUOTE(buddy @ 9 Nov 2011 7:20 PM)
    Hey,....I saw your posts in the other forums.  I can't say anything definite about the popularity of the Yahoo Connected platform.  Certainly support is dificult to come by.  Devici and some others used to offer some free code on their site but it's since become paywalled.  My client has requested develpoment on this platform solely in the name of market permeation; despite Yahoo's boasts of a install base in the millions, they are not expecting much in terms of users.

    Your issue is happening because you are referencing the variable playlist.ID.  This line:
    for each(var playlist in playlists) {
    redefines the variable playlist as each item in the playlists array.  After the loop has finished, the variable playlist remains as the last array item.  Thus, subsequent calls to the variable playlist will always be tied to the last item in the array.

    What you need to do is alter your onSelect event.  I recommend something like this:
    onSelect: function(event) {
         var pid=this.id.split('_').pop();
         KONtx.application.loadView('view-Player', { PlaylistID: pid });
    }

    When you use the this keyword in an event like onSelect, onBlur, etc. it references that control.  Since you had the foresight to include each playlists ID in an underscore delimited variable, you can easily isolate the desired id by using the Javascript functions split() and pop()


    QUOTE(Daniel @ 9 Nov 2011 4:49 PM)
    Anyone out there in Yahoo land??
    0

Recent Posts

in Design / Interaction - Yahoo! TV Widgets