Results 1 to 3 of 3
  1.    #1  
    So far every question I've asked has had zero replies but hopefully this one will get some. I am using the showAlertDialog. I have an array I call item[x]. Its amount of items in it will vary.

    looking at the same code
    Code:
    	  
    this.controller.showAlertDialog({
    	    onChoose: function(value) {this.controller.get("area-to-update").update("Alert result = " + value);},
    	    title: $L("Friends"),
    	    message: $L("Which Friend?"),
    	    choices:[
    	         {label:$L('item 1'), value:"i1"},  
    	         {label:$L('item 2'), value:"i2"},
    	         {label:$L('item 3'), value:"i3"},    
    	         {label:$L('item 4'), value:"i4"}    
    	    ]
    	    });
    I would like to be able to do something like this where varNumItems is the number of items in the array:
    Code:
    this.controller.showAlertDialog({
    	    onChoose: function(value) {this.controller.get("area-to-update").update("Alert result = " + value);},
    	    title: $L("Friends"),
    	    message: $L("Which Friend?"),
    	    choices:[
                     for (k = 0; k < varNumItems; k++)
                       {
    	               document.write('{label:$L('+item[x]+'), value:'+item[x].substr(2)+'},')  
    	            }     
    	         {label:$L('cancel'), value:"cancel"}    
    	    ]
    	    });
    Any help would really be appreaciated or someplace I can look, even some sample code. Thank you
  2. #2  
    Why not do something like this...

    Code:
    // CREATE VARIABLE TO HOLD CHOICES
    
    	var yourChoices = '[';
    
    	for (k = 0; k < varNumItems; k++)
    	{
    		yourChoices += '{label:$L(' + item[k] + '), value:' + item[k].substr(2) + '},');
    	}     
    
    	yourChoices += "{label:$L('cancel'), value:'cancel'}]";
    
    // CREATE DIALOG USING CHOICE VARIABLE
    
    	this.controller.showAlertDialog({
    			onChoose: function(value) {this.controller.get("area-to-update").update("Alert result = " + value);},
    			title: $L("Friends"),
    			message: $L("Which Friend?"),
    			choices: yourChoices.toJSON()
    			});
    Last edited by Laxidasical; 10/22/2009 at 08:02 PM. Reason: Code fix
    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  
    Well, first, let's lose the document.write, since you're not WRITING the buttons in the alert dialog,the mojo FRAMEWORK is writing them.

    second, you need to quit hard-coding the choices and make them a variable...

    So, let's change the call to the setup to look like this:

    Code:
    this.controller.showAlertDialog({
    	    onChoose: function(value) {this.controller.get("area-to-update").update("Alert result = " + value);},
    	    title: $L("Friends"),
    	    message: $L("Which Friend?"),
    	    choices: choicearray 
    	    });
    Then, before you call the showAlertDialog you need to set up your choice array....

    Code:
    choicearray = [];
    for (k = 0; k < varNumItems; k++)
                       {
                           buttonObject =  { label: $L(item[x]), 
                                                value: item[x].substr(2) };
    
    	               choicearray.append(buttonObject);
    	            }     
    choicearray.append({label: $L('cancel'), value: 'cancel'} );
    so that when you call the dialog you pass it the array of button objects....

Posting Permissions