0

我是 ZK 的新手。我需要动态创建带有标签的 N 组合框并填充它们。我已经用它的 id 填充了一个组合框,但是由于可能有很多组合框,我不应该知道它们的 id,所以它不能解决我的问题。

我需要添加 N 个组合框,它们的标签并动态填充它们。有没有办法创建那组组合框并动态设置它们?有任何想法吗?

下面的代码用于填充已经知道其固定 ID 的组合。

//In this example I assume I have a label and a combobox. But could have 0 to N of them.

private Label lblComboMetadatos;
private Combobox cmbMetadatos;

//THEN

if (cmbMetadatos.getItemCount() == 0) {
  lblComboMetadatos.setValue(trdMetaTipoDocumental.getNombreMetadato()); //Here I set the name of label but I should really can not know how many of them could be. There may exist 0..N 
  for (TrdMetadato trdMetaDato: trdMetaTipoDocumental.getTrdMetadatos()) {

    String enumValores = trdMetaDato.getValoresEnumerado(); //Here I set the values of a combobox but I can not know how many of them could be. There may exist 0..N  
    cmbMetadatos.appendItem(enumValores]);
}

}
<zk>
  <window id="idWindow" title="nameWindow" apply="controller.java" border="normal" closable="true" sizable="true" maximizable="true" maximized="true" height="85%" width="150%" style="overflow:auto;">
    <!-- CONTINUES -->
    <groupbox>
      <hlayout>
        <label id="lblComboMetadatos" />
        <combobox id="cmbMetadatos"></combobox>
      </hlayout>
    </groupbox>
    <!-- CONTINUES -->
  </window>
</zk>
4

1 回答 1

1

这个问题和你上一个问题非常相似。您应该将父容器(hlayout在这种情况下)连接到您的控制器,然后在那里创建组件。

@Wire
private Component container; // your hlayout

@Override  // This method should be specified by a composer super class
public void doAfterCompose(Component comp) throws Exception
    for (<count an index or loop over data>) {
        hlayout.appendChild(new Label("Hello World");
        Combobox cb = new Combobox();
        // append Comboitems
        cb.addEventListener(Events.ON_SELECT, ...);
        hlayout.appendChild(cb);
    }
}

如果您使用 MVVM,则可以使用子绑定在 zul 中创建组件。

于 2017-07-05T08:32:00.020 回答