tags:

views:

104

answers:

1

Here's my code:

var sb = new qx.ui.form.SelectBox();

sb.add( new qx.ui.form.ListItem("English") );
sb.add( new qx.ui.form.ListItem("Nederlands") );
sb.add( new qx.ui.form.ListItem("Deutsch") );
sb.add( new qx.ui.form.ListItem("français") );
sb.add( new qx.ui.form.ListItem("Српски") );

How do I use setSelection() to select "Deutsch", and what if the items are numeric values? Can I also set values for these labels or is SelectBox() limited to labels?

For example:

value: en, label: English
value: de, label: Deutsch
etc.
+5  A: 

Take a look at the example code below.

You can specify a model with each ListItem for storing additional information. It can act as value property on form items for example. See http://demo.qooxdoo.org/1.0.x/apiviewer/#qx.ui.form.ListItem

  var selectBox = new qx.ui.form.SelectBox();

  selectBox.add( new qx.ui.form.ListItem("English", null, "en" ));
  selectBox.add( new qx.ui.form.ListItem("Nederlands", null, "nl" ));
  var defaultItem = new qx.ui.form.ListItem("Deutsch", null, "de" );
  selectBox.add(defaultItem );
  selectBox.add( new qx.ui.form.ListItem("français", null, "fr"));
  selectBox.add( new qx.ui.form.ListItem("Српски", null, "ru"));

  selectBox.setSelection([defaultItem]);
  selectBox.addListener("changeSelection", function(e) {

    //Read model data from listitem
    this.debug("changeSelection: " + e.getData()[0].getModel());
  });
dashhunter