Combobox 从ODATA调用中选择组合框中的第一项。UI5
我有一个组合框,由一个odata调用填充 在主页中,我导航到带有此组合框的页面,并希望此组合框选择ODATA调用的第一项作为默认/选定项 我使用bindAggregation填充Combobox 从ODATA调用中选择组合框中的第一项。UI5,combobox,sapui5,Combobox,Sapui5,我有一个组合框,由一个odata调用填充 在主页中,我导航到带有此组合框的页面,并希望此组合框选择ODATA调用的第一项作为默认/选定项 我使用bindAggregation填充onInit()函数中的组合框 绑定对象后,我想阅读列表并选择第一个对象 bindComboBox: function() { var comboBox = oView.byId("ComboBoxID"); comboBox.bindAggregation("items", { path
onInit()函数中的组合框
绑定对象后,我想阅读列表并选择第一个对象
bindComboBox: function() {
var comboBox = oView.byId("ComboBoxID");
comboBox.bindAggregation("items", {
path: path,
parameters: param,
sorter: sorter,
template: template,
filters: filter,
events: {
dataReceived: this.selectFirstItemFunction()
}
}
selectFirstItemFunction: function() {
var comboBox = oView.byId("ComboBoxID");
var comboBoxItems = comboBox.getItems(); // This ends up being undefined.
comboBox.setSelectedItem(comboBoxItems[0]);
}
执行此操作时,selectFirstItemFunction()
中的var comboBoxItems
始终为空/未定义
我还尝试将selectFirstItemFunction()
放在onAfterRendering()
中,但也没有成功
如果页面已经加载,并且我选择了FirstItemFunction()
,则组合框将按预期工作
关于如何正确加载组合框有何想法?您没有将“selectFirstItem”功能附加到事件。执行“bindComboBox”时直接调用它
用以下方法更正它:
dataReceived: this.selectFirstItemFunction.bind(this)
但要小心,因为如果数据已经缓存,则可能不会触发“dataReceived”。所以也许你想使用“改变”事件
您没有将“selectFirstItem”功能附加到事件。执行“bindComboBox”时直接调用它
用以下方法更正它:
dataReceived: this.selectFirstItemFunction.bind(this)
但要小心,因为如果数据已经缓存,则可能不会触发“dataReceived”。所以也许你想使用“改变”事件