首页 > 解决方案 > 如何在 sapui5 中设置组合框下拉列表的高度?

问题描述

我需要在 sapui5 的组合框中为下拉列表设置最大高度。我已尝试使用以下代码。

#comboBox1-popup.sapMPopover {
    max-height: 400px;
  
}

#comboBox1.sapMPopoverScroll {
    max-height: 400px !important;
    
}

通过 css 我无法为项目中的特定组合框设置高度。当我尝试“sapMPopover”时,它会改变我整个项目中所有组合框的高度。我想为特定的组合框设置最大高度。提前致谢。

标签: csscomboboxsapui5

解决方案


因为现在有 max-height 的直接属性或从 xml 访问弹出框。您需要等到弹出列表初始化后才能从 ComboBox 获取它并向其添加自定义类。

在页面控制器中

onAfterRendering: function(){
  this.exec(this);
},

exec: function(self){
  var oCombo = self.getView().byId("MyComboBox"),
  oPopOver = oCombo.getList();
  if(oPopOver !== null
    && oPopOver !== undefined){
    oPopOver.addStyleClass("test");
  }else{
    setTimeout(self.exec, 1, self);

  }
}

在 css 文件中,您现在可以编写

.test {max-height: 100px !important;}

推荐阅读