Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By nyuepik
  1. monotok's Avatar
    Posts
    24 Posts
    Global Posts
    278 Global Posts
       #1  
    Hello I am new to the whole javascript/mojo development for webos. I have so far created a app that has a main screen with three buttons. When you click on one of the buttons it takes you to another scene.

    For one scene called 'binaryScene' I am trying to display a list from a javascript array.

    Here is the array:

    var dec = new Array(256);
    var i=0;

    for(i=0;i<256;i++)
    {
    dec[i]=i;
    }

    Now I have not found any tutorials, blogs that use this type of array for webOS development. They all seem to use this:

    this.listItems = [
    {
    title: "Cookie"
    },
    {
    title: "Depot"
    },
    {
    title: "SqLite"
    }
    ];
    Here is the binaryScene file:


    function BinarySceneAssistant() {

    var dec = new Array(256);
    var i=0;

    for(i=0;i<256;i++)
    {
    dec[i]=i;
    }

    }

    BinarySceneAssistant.prototype.setup = function() {
    this.controller.setupWidget("binaryListWgt",
    {
    itemTemplate: "binaryScene/binaryRowTemplate",
    listTemplate: "binaryScene/binaryListTemplate",
    swipeToDelete: false,
    renderLimit: 40,
    reorderable: false
    },
    this.model = {
    items : this.listItems
    }
    );

    this.binaryListHandler = this.loadArraydec.bindAsEventListener(this);
    this.controller.listen("binaryListWgt", Mojo.Event.listTap, this.binaryListHandler);

    }

    BinarySceneAssistant.prototype.loadArraydec = function(event)
    {

    }

    BinarySceneAssistant.prototype.activate = function(event) {
    /* put in event handlers here that should only be in effect when this scene is active. For
    example, key handlers that are observing the document */
    };

    BinarySceneAssistant.prototype.deactivate = function(event) {
    /* remove any event handlers you added in activate and do any other cleanup that should happen before
    this scene is popped or another scene is pushed on top */
    };

    BinarySceneAssistant.prototype.cleanup = function(event) {
    Mojo.Event.stopListening(this.controller.get("binaryListWgt"), Mojo.Event.listTap, this.binaryListHandler);
    };

    This is really annoying me
    I want the list to display the numbers from the array 0 - 255.
    I dont want to type out Title: "0", 256 times tbh!

    My eventual goal with this would be to have three columns of Decimal, Hexadecimal and Binary so the user can scroll the list and see side by side the conversions of each (Like in a table).
    Hope that makes sense!
    Thanks
  2. #2  
    in this snippet:

    this.model = {
    items : this.listItems
    }

    have you tried replacing this.listItems with this.dec or dec? If so, what do you see?
  3. monotok's Avatar
    Posts
    24 Posts
    Global Posts
    278 Global Posts
       #3  
    Hello,
    When i tried that the button to get to the binary scene does not click/work at all.
    However i tried as shown in the attachments and it takes me to the binary scene but does not display anything.

    function BinarySceneAssistant() {

    var dec = new Array(256);
    var i=0;

    for(i=0;i<256;i++)
    {
    dec[i]=i;
    }
    return dec
    }

    BinarySceneAssistant.prototype.setup = function(dec) {
    this.controller.setupWidget("binaryListWgt",
    {
    itemTemplate: "binaryScene/binaryRowTemplate",
    listTemplate: "binaryScene/binaryListTemplate",
    swipeToDelete: false,
    renderLimit: 40,
    reorderable: false
    },
    this.model = {
    items : this.setup(dec)
    }
    );

    this.binaryListHandler = this.loadArraydec.bindAsEventListener(this);
    this.controller.listen("binaryListWgt", Mojo.Event.listTap, this.binaryListHandler);

    }

    I thought maybe i have to return the array from the assistant and then import to the setup function?

    The screen attachments show the main screen and the binary scene.
    Thanks
    Attached Images Attached Images
  4. #4  
    Yeah, you have multiple problems in your code.

    First, you are not saving your array at all. You should be working with this.dec not var dec. var dec has a local scope to your constructor.

    Next, you shouldn't really be calling "this" from inside the controller widget, although I don't think that is your problem.

    I would not start working with the list widget until you get a handle on the basic JavaScript. Run through the tutorial at W3Schools before you try Mojo. It will be much better for you.
  5. #5  
    I agree with nyuepik. If you don't know how to figure things like this out for yourself w/o asking them here then it's a good idea to go through the tutorials first. Not saying that we're not going to help you out here =p we'll do the best we can but I would really read up on it. There's a lot to learn.
    Neo Enyo 2.0 Twitter App: NOW AVAILABLE | WON REVIEW
    clearview - clear card app for HP TOUCHPAD
    Wild'n Video Poker - AVAILABLE FOR ALL WEBOS DEVICES! | follow for latest updates - @fxspec06

  6. monotok's Avatar
    Posts
    24 Posts
    Global Posts
    278 Global Posts
       #6  
    I'll have another look at the tutorials but they array tutorials don't seem to show the one I used just the other one:

    var myCars=new Array(); // regular array (add an optional integer
    myCars[0]="Saab"; // argument to control array's size)
    myCars[1]="Volvo";
    myCars[2]="BMW";

  7. #7  
    BTW

    arrays with a length of 256 end at 255
    Code:
    var dec = new Array(256);
    var i=0;
    
    for(i=0;i<256;i++)
    {
    dec[i]=i;
    }
    return dec
    }
    should be

    Code:
    var dec = new Array(256);
    var i=0;
    
    for(i=0;i<255;i++)
    {
    dec[i]=i;
    }
    return dec
    }
    this would cause your scene to never be pushed.
    Neo Enyo 2.0 Twitter App: NOW AVAILABLE | WON REVIEW
    clearview - clear card app for HP TOUCHPAD
    Wild'n Video Poker - AVAILABLE FOR ALL WEBOS DEVICES! | follow for latest updates - @fxspec06

  8. monotok's Avatar
    Posts
    24 Posts
    Global Posts
    278 Global Posts
       #8  
    Thank you, now I have modified the code using:

    this.dec = dec;

    and items: this.dec

    I seem to have the list working!! The scene loads up and you can see the 255 rows for the list but no numbers actually appear.
    I presume this is because there is no label or title for the list to display.

    Hopefully it will all come together soon and I learn fast ahaha.
    I must say learning C++ with the command promt was much easier
  9. #9  
    FX:

    Actually, <256 is correct, <=256 would be wrong. Additionally, JavaScript will dynamically resize the array if you start referencing indicators beyond your initial allocation, so that shouldn't throw an Exception. As a C guy, it makes my skin crawl, but I see the attraction.
    fxspec06 likes this.
  10. #10  
    Monotok:

    If you are a C guy, make sure you understand closures. It was such a foreign concept and so counter-intuitive to people who come from other languages.

    JavaScript Closures 101- they're not magic

Posting Permissions