0

Error in tutorial code

I was banging my head against the wall trying to understand the logic of the following section of code.


CODE
updateView: function() {
var arr = [];
for (var i = 0; i < (this.config.visibleRows * 2); i++) {
arr.push({
label: 'Button ' + (i + 1),
buttonNumber: i,
});
}
this.controls.listGrid.changeDataset(arr);
}


What made no sense is that visibleRows is set to 3. Why is it being multiplied by 2 which would create an array of 6 buttons when only 3 are visible? If you remove the multiplier you get the same exact results (3 visible buttons). So I finally came to the conclusion that this is simply a coding error in the sample widgets.

If I am wrong, please let me know. Otherwise, I will chalk this one up to wasted time.

by
5 Replies
  • Many of the code samples are from actual (or legacy) widgets or from the framework and would be doing as instructed per its application logic.

    Where did you find this code? Is it from the online docs or the pdf that comes with the wdk? What page number?
    0
  • QUOTE (Benjamin Toll @ Jan 25 2011, 09:58 AM) <{POST_SNAPBACK}>
    Many of the code samples are from actual (or legacy) widgets or from the framework and would be doing as instructed per its application logic.

    Where did you find this code? Is it from the online docs or the pdf that comes with the wdk? What page number?


    It is from the the wdk: com.yahoo.widgets.tv.toolbox.widget --> ToolboxGridTestView.js.
    0
  • QUOTE (seekersedge @ Jan 25 2011, 06:52 AM) <{POST_SNAPBACK}>
    What made no sense is that visibleRows is set to 3. Why is it being multiplied by 2 which would create an array of 6 buttons when only 3 are visible? If you remove the multiplier you get the same exact results (3 visible buttons). So I finally came to the conclusion that this is simply a coding error in the sample widgets.

    If I am wrong, please let me know. Otherwise, I will chalk this one up to wasted time.

    It's not an error, it's demonstrating that a grid can have paged results. You can do this by creating more rows than are visible per page (3 in this example).
    0
  • QUOTE (Benjamin Toll @ Jan 25 2011, 11:44 AM) <{POST_SNAPBACK}>
    It's not an error, it's demonstrating that a grid can have paged results. You can do this by creating more rows than are visible per page (3 in this example).



    I thought about that, but there is no PageIndicator with that specific example.
    0
  • QUOTE (seekersedge @ Jan 25 2011, 12:59 PM) <{POST_SNAPBACK}>
    I thought about that, but there is no PageIndicator with that specific example.

    True, there's an argument that should have been included for a visual clue.
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets