Model 填写组合框列表

Model 填写组合框列表,model,qml,Model,Qml,在更新已经存在的应用程序时,我尝试在自动生成的对话框的每一行中添加一个组合框。 对话框将从外部QML接收其数据,行数可能不同 代码基本上看起来像 { contentItem: Column Repeater { model: valueModel delegate: Row { function fillComboBox() { var choices = ChoiceListElement.choice

在更新已经存在的应用程序时,我尝试在自动生成的对话框的每一行中添加一个组合框。 对话框将从外部QML接收其数据,行数可能不同

代码基本上看起来像

{
  contentItem: Column
  Repeater
  {
     model: valueModel
     delegate: Row
     {

       function fillComboBox()
       {
          var choices = ChoiceListElement.choices;
          if(typeof choices !== "undefined")
          {
            for(var i = 0; i < choices.length; i++)
            {
               comboboxModel.append({text: choices[i]});
            }
         }
       }

       Item
       {
              Component.onCompleted:
              {
                 fillComboBox();
              }
       }
       function format()
       {
          var formatted_string = name;
          return formatted_string;
       }
       Text
       {
         text: format()
       }
       ComboBox
       {
         id: combo
         width: 50
         model: comboboxModel
       }
     }
  }
ListModel
{
    id: comboboxModel
}
有什么想法吗

提前谢谢

迈克尔

更新:

  • 上面代码中的固定委托,已如上面原始代码中所示
  • 添加了显示如何填充组合框模型的代码

我建议将“comboboxModel”的声明移到学员的内部,以便为每个ComboxBox创建新的模型。

选项A、B、C、D来自哪里?另外,文本和
组合框
不是包装在您实际代码中的单个代表
中吗?谢谢您的提问,GrecKo,我已经更新了示例。
content Combobox 1:
 * option A
 * option B

content Combobox 2:
 * option C
 * option D