Sitecore SPEAK UI programmatically sets the selected ComboBox item

How to set selected item of ComboBox component in Sitecore SPEAK UI?

My ComboBox is populated with the QueryDataSource component, which looks at the items folder in my base database.

I can get the current selected value (this is text, not identifier) ​​using the following code:

var value = this.MyComboBoxId.viewModel.selectedItemId();

and I expected that I could set the selected value using:

var value = "SomeValueWhichExistsInTheList";
this.MyComboBoxId.viewModel.selectedItemId(value);

but this does not seem to work. The documentation here mentions use

rebind(items, selectedItem, selectedValue, displayFieldName, valueFieldName)

but I don’t want to re-fill it, just change the selected item. My code is in the method of initializemy model.

Edit

, ComboBox DisplayFieldName ValueFieldName, , itemId. DisplayFieldName / ValueFieldName - .

+4
2

initialize :

app.yourQueryDataSource.on("change:hasItems", function () {
    app.yourComboBox.set("selectedValue", yourValue); 
});
+2

,

app.<yourcontrolid>.viewModel.rebind()
Hide result

Sitocore SPEAK combobox, .

0

All Articles