Sitecore SPEAK UI 以编程方式设置 ComboBox 的选定项
Sitecore SPEAK UI programmatically set selected item of ComboBox
如何在Sitecore SPEAK中设置ComboBox组件的选中项UI?
我的 ComboBox 由一个 QueryDataSource 组件填充,该组件正在查看我的核心数据库中的项目文件夹。
我可以使用以下代码检索当前选择的值(文本,而不是 ID):
var value = this.MyComboBoxId.viewModel.selectedItemId();
我希望能够使用以下方法设置所选值:
var value = "SomeValueWhichExistsInTheList";
this.MyComboBoxId.viewModel.selectedItemId(value);
但这似乎不起作用。文档 here 提到使用
rebind(items, selectedItem, selectedValue, displayFieldName, valueFieldName)
但我不想重新填充它,只需更改所选项目即可。我的代码在模型的 initialize
方法中。
编辑
我发现如果 ComboBox 在呈现属性中没有设置 DisplayFieldName
或 ValueFieldName
值,您必须将值设置为适当的 itemId。 DisplayFieldName
and/or ValueFieldName
应设置为您创建的字段的名称 - 您不能绑定到项目名称。
在initialize
方法中,使用以下代码设置值:
app.yourQueryDataSource.on("change:hasItems", function () {
app.yourComboBox.set("selectedValue", yourValue);
});
以上方法对我不起作用,因此我使用了
app.<yourcontrolid>.viewModel.rebind()
功能如 Sitecore SPEAK 组合框文档中所述,并且有效。
如何在Sitecore SPEAK中设置ComboBox组件的选中项UI?
我的 ComboBox 由一个 QueryDataSource 组件填充,该组件正在查看我的核心数据库中的项目文件夹。
我可以使用以下代码检索当前选择的值(文本,而不是 ID):
var value = this.MyComboBoxId.viewModel.selectedItemId();
我希望能够使用以下方法设置所选值:
var value = "SomeValueWhichExistsInTheList";
this.MyComboBoxId.viewModel.selectedItemId(value);
但这似乎不起作用。文档 here 提到使用
rebind(items, selectedItem, selectedValue, displayFieldName, valueFieldName)
但我不想重新填充它,只需更改所选项目即可。我的代码在模型的 initialize
方法中。
编辑
我发现如果 ComboBox 在呈现属性中没有设置 DisplayFieldName
或 ValueFieldName
值,您必须将值设置为适当的 itemId。 DisplayFieldName
and/or ValueFieldName
应设置为您创建的字段的名称 - 您不能绑定到项目名称。
在initialize
方法中,使用以下代码设置值:
app.yourQueryDataSource.on("change:hasItems", function () {
app.yourComboBox.set("selectedValue", yourValue);
});
以上方法对我不起作用,因此我使用了
app.<yourcontrolid>.viewModel.rebind()
功能如 Sitecore SPEAK 组合框文档中所述,并且有效。