1

I'm new to Titanium so maybe my question is a newbie one, but I'm trying to dynamically populate an option Dialog (use Alloy framework). Is it possible to create a new ArrayCollection and pass it to my optionDialog like this :

<OptionDialog id="dialog" title="Choose Calendar" src=getAllCalendars>
        <Options>
            <Option id="{calendar_id}">{calendar_name}</Option>
        </Options>
   </OptionDialog>

Where getAllCalendar is a function that return a new Array Collection.

I know I've done things like this before in Flex but I can't make it work on Titanium so maybe it isn't the right way.

Thank you for your answers.

Fabrice Lefloch
  • 409
  • 4
  • 16

2 Answers2

1

You need to write code in js file in Appcelerator(Alloy).

For that way you can easily get that click events.

var dialog = Ti.UI.createOptionDialog({
        options : options,//Array
        title : 'Hi <?'
    });
    dialog.show();

    dialog.addEventListener('click', function(_d) {
        onclickactions[_d.index];
    });
Dharmik Patel
  • 76
  • 1
  • 11
0

I came up with this. If you opt to just create the dialog box, which works in alloy using the classic method, you can do this.

For me, the key part was to keep the order of the options with my options array. After the option was selected, you could then reference the options array with the e.index to find which was selected.

function companyDialog(){
    // Build the list of options, maintaining the position of the options.
    if(Alloy.Globals.Form){
        Alloy.Globals.Form.Controller.destroy();
    }
        // My list of companies returns companyname, companycode, id
    companies = db.listCompanies();
    var options = [];

    _.each(companies, function(val){
        options.push(val.companyname + " (" + val.companycode + ")");
    });
    options.push("Cancel");

    var dialog = Ti.UI.createOptionDialog({
        title : 'Companies',
        options : options
    });

    dialog.addEventListener('click', function(e) {
        var setCode = "";
        var selection = "Unknown";
        if(options[e.index] != "Cancel") {
                    // DO WORK HERE.
                    alert(options[e.index].companyname);
        }
    });
    dialog.show();
}
Martin
  • 1,914
  • 1
  • 12
  • 14