我使用ui-select填充一些数据作为选择,数据存储在对象数组"pageArray"中,对象看起来像这样
{
pageName: pageNameArray
}
,
[{"alpha": [1,2,3,4]}, {"beta":[3,4,5,6,7]}, {"gamma": [6,4,2,0]}, ....]
现在在ui-select中,我想要显示选项为"alpha","beta","gamma",…基本上是键值,我该怎么做?
我现在使用的ui-select代码是这个
<ui-select ng-model = "page1.selected" style="width: 200px;" on-select = "getHost1List()">
<ui-select-match placeholder = "Choose a page">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat = "page in pageArray | filter: {name: $select.search}">
<span ng-bind-html = "page.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
还是有更好的方法?
基本上在ui-select中,我想给选择["alpha", "beta", "gamma", ....]。当我们选择一个特定的名称时,相应的对象应该被选中,例如,如果我们在列表中选择"alpha",则
page1.selected = { {"alpha": [1,2,3,4]} }
你可以这样做,把你的对象格式改成这个
{
"name": pageName,
"data": pageNameArray
}
在ui-select中,您可以仅以"name"的形式查询给定选项(假设数组的名称为"arr"
)。<ui-select ng-model = "page1.selected" style="width: 200px;" on-select = "getHost1List()">
<ui-select-match placeholder = "Choose a page">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat = "page in array | filter: {name: $select.search}">
<span ng-bind-html = "page.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
当选择项被选中时,对象也被选中,因此您甚至可以访问所选对象的"数据"