在AngularJS中重新排序所选项目ui-select multiple

时间:2017-01-21 18:53:28

标签: javascript angularjs angular-ui-select

是否可以在AngularJS中自动重新排序选定的项目ui-select of type multiple?

以下是代码示例,ui-select github

还有更多内容
public override string ToString(this string reservatiestring)
{

    reservatiestring = "Kamer: " + roomNumber + "" + "  Op datum: " + datum + "  Aantal personen: " + personen.Count + "  Naam: " + reservatienaam;
    return reservatiestring;
}

以下是其行为的屏幕截图:

enter image description here

我想要的是要重新排序的所选项目:即使我选择的项目我先选择黄色,然后是绿色,然后是蓝色,我希望它是蓝色,绿色,黄色。

我看过一个名为sortable =“true”的属性,但它似乎没有按照我的预期行事。

1 个答案:

答案 0 :(得分:1)

尝试添加on-select="$select.selected.sort()"

<ui-select multiple 
         ng-model="ctrl.multipleDemo.colors" 
         on-select="$select.selected.sort()"
         theme="bootstrap" 
         ng-disabled="ctrl.disabled" 
         close-on-select="false" 
         style="width: 300px;" 
         title="Choose a color">
  <ui-select-match placeholder="Select colors...">{{$item}}</ui-select-match>
  <ui-select-choices repeat="color in ctrl.availableColors | filter:$select.search">
    {{color}}
  </ui-select-choices>
</ui-select>

更新了plunker:http://plnkr.co/edit/Bms3pDdn6XnS2b7gsyQ5?p=preview