Javascript 当实际选项低于Optgroups应使用的选项时,使用ui选择Optgroups(新版本)

Javascript 当实际选项低于Optgroups应使用的选项时,使用ui选择Optgroups(新版本),javascript,angularjs,angularjs-directive,angularjs-ng-repeat,ui-select2,Javascript,Angularjs,Angularjs Directive,Angularjs Ng Repeat,Ui Select2,我将UI Select(select2主题)与以下形式返回的数据数组一起使用: Array of Objects [ 0: Object { category: "Category name, to be used as optgroup label", options: [ 0: Object { id: 5, name: "Some name, to be

我将UI Select(select2主题)与以下形式返回的数据数组一起使用:

Array of Objects [
    0: Object {
         category: "Category name, to be used as optgroup label",
         options: [
             0: Object {
                 id: 5,
                 name: "Some name, to be used as an option under the above optgroup",
             }
             1: Object {
                 id: 6,
                 name: "Some name, to be used as an option under the above optgroup",
             }
             2: Object {
                 id: 7,
                 name: "Some name, to be used as an option under the above optgroup",
             }
         ]
    }
    1: Object {
         category: "Another category name, to be used as second optgroup label",
         options: [
             0: Object {
                 id: 44,
                 name: "Some name, to be used as an option under the above optgroup",
             }
             1: Object {
                 id: 45,
                 name: "Some name, to be used as an option under the above optgroup",
             }
             2: Object {
                 id: 47,
                 name: "Some name, to be used as an option under the above optgroup",
             }
         ]
    }
]
创建optgroups的My函数:

$scope.createOptGroups = function(item){
    return item.category;
};
它确实正确地创建了我的optgroup

这里的问题如下。要创建OptGroup,我需要处于以下级别:

<ui-select multiple ng-model="diseaseObject.chosenDiseases.states">              
    <ui-select-match placeholder="Start typing disease name or click in the box...">{{$item}}</ui-select-match>
        <ui-select-choices
            group-by="createOptGroups" 
            repeat="state in diseaseObject.allStates | filter: $select.search track by $index">

            {{state}}

        </ui-select-choices>                                
</ui-select>

{{$item}}
{{state}}
如果您想知道这段代码的结果是什么,请看这张图片:

因此,很明显,数据已经存在,但需要缩小到所需的diseaseName属性。 但是如果我这样做,我将失去optgroups!我将不再处于
类别
属性可用的级别。 另一个想法是缩小
状态
的范围,比如:
state.options
。但是这个值仍然是一个需要迭代的对象数组。但是,如果有一个选项可以为实际选项实现另一个中继器(目的是实现类似于
{{name}}
)的功能,那就可以了。我已经尝试过了,但是指令(ui select)不喜欢它

他们有一个官方的演示来演示这个
groupby
的东西,但是在这个特殊的例子中,函数只是将optgroups创建为自定义字符串(字母跨度),这与我的问题非常不同


请参阅最下面的示例:

太糟糕了,这个问题没有得到足够的关注。我相信这会很有用,至少有人能解释一下这是否可行。我提前感谢这样的人!我在搜索与ui select相关的内容时遇到了你的问题。如果太晚了,请原谅:)没有办法实现满足您的用例的中继器。然而,我相信你的问题的答案取决于你想要实现的模型。i、 根据你的解释,我假设你的模型就是疾病对象。如果是这种情况,那么你可以通过对每个疾病对象进行分类来解决你的问题。这样,您就不会丢失optgroup,并且您可以允许用户选择一种疾病。