Results 1 to 8 of 8
  1.    #1  
    Sorry for my poor English.I am learning to develop a calculator for webos devices.but there's a problem that I don't know how to get the 'label' of a wiget button within the user interface in a function.
    Could some one kind guy give me the answer?
    Last edited by EKSON; 03/08/2010 at 04:02 AM. Reason: don't discrible clearly.
  2. #2  
    What do you mean by tag name? Do you mean the id value in your div tag? Can you show an example of your code?
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  3.    #3  
    sorry,I didn't describle the problem clearly.
    I want to get the id info about a button. In the scence's assistant setUp function,I use a for-loop to initiate the number button(0-9). In the button's tap event handler function, I should get the button's id or the label to determine which button been tapped. Following is the sample code.
    In assistant setUp function:
    FirstAssistant.prototype.setUp=function() {
    for(i=0;i<10;i++) {
    this.model={};
    this.attributes={};
    this.model={
    "lable":i,
    "buttonId":i,
    "disable":false}
    ;
    this.controller.setUp("Mybutton",this.attributes,this.model);
    Mojo.Event.listen(this.controller.get("i"),Mojo.Event.tap,this.handleButtonPress.bind(this));
    //
    }
    }

    FirstAssistant.prototype.handleButtonPress=function(event){
    //code for get the info of*buttons.Help me!
    }
  4. #4  
    In handleButtonPress, you would look for

    event.target.id



    As a related issue, please make sure to set up a handler reference in your assistant initialize.constructor method.

    In the assistant initialize method, you put

    this.onTap_MyButtonHandler = MyButtonHandler.bind(this);

    then in your assistant setup function, you put


    this.controller.setUp("Mybutton",this.attributes,this.model);
    Mojo.Event.listen(this.controller.get("Mybutton"),Mojo.Event.tap,this.onTap_MyButtonHandler );


    This will avoid multiple instances of the same method.

    This is a Palm best practice as explained below


    Callback Handlers

    With every call to bind(), you create a new function. So, make the call once in initialize, and then reuse that same one every time. However, remember that pre-caching only works if the arguments that you are binding the method to do not change. If you need to bind it to different arguments every time, you cannot pre-cache.
    Last edited by Blubble; 03/08/2010 at 09:26 AM.
  5.    #5  
    Thank you so much.But when I use event.target.I'd, I get the following result for example:
    palm_anon_element_0 mojo-scence-first Mybutton-buttonLabel.I just want Mybutton,cause "Mybutton" is the id of the button.
  6. #6  
    Gotcha, the object of the button pressed is passed to your handleButtonPress function, and in this case is called "event". Try this...

    Code:
    FirstAssistant.prototype.handleButtonPress=function(event)
    {
        var selected = this.model.items[event.index]; // make sure model name matches
        var MyButton = selected.buttonId; // access all model elements like this
    }
    Last edited by Laxidasical; 03/08/2010 at 11:48 PM.
    MoBill - Use your Authorize.net account to bill your customers with your webOS device!!
    MoJack - Track your lost or stolen webOS device from anywhere!
    Time to get VIRAL
  7.    #7  
    thank you, Laxidasical.you mean I can use this method to get the button's id? But I tried it, and it doesn't work. Maybe I should check out the handleButtonPress function's code carefully.
  8.    #8  
    is the "model" a property for the scence, Laxidasical?

Posting Permissions