pra*_*pds 5 javascript angularjs ui-select2 ui-select
题 :
如何将默认值设置为角度ui-select
从对象和对象获取的下拉值不具有默认值.
和ui-select应该在前端设置默认值.
例如:
下拉值如下
1 -all fruits 2 -apple 3 -banana 4-water melon
从2到4的值是从服务器发送的对象派生的.但是前端需要设置默认值,即1 - 所有水果
通过ui-select2参考下面的示例集如何在ui-select中迁移它?
<select ng-model="fID" class="select" ui-select2 data-placeholder="select fruit">
<option value="">All fruits</option>
<option ng-repeat="f in frits value="{{f.fID}}">{{f.name}}</option>
</select>
<ui-select theme="select2" ng-model="fruits.selected">
<ui-select-match placeholder="select please" allow-clear="false"> {{$select.selected.name}}
</ui-select-match>
<ui-select-choices repeat="f in fruits | filter:$select.search">
<div ng-bind-html="f.name | highlight: $select.search:'underline'"></div>
</ui-select-choices>
</ui-select>
Run Code Online (Sandbox Code Playgroud)
http://plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview https://github.com/angular-ui/ui-select 链接:angular-ui/ui-select
您没有使用 id 或类似的选项值,因此 ui-select 会比较对象地址以了解它是否被选中。
\n\nvar p1 = { name: 'Adam', email: 'adam@email.com', age: 10 };\n $scope.person = {selected: p1};\n $scope.people = [\n p1,\n { name: 'Amalie', email: 'amalie@email.com', age: 12 },\n { name: 'Wladimir', email: 'wladimir@email.com', age: 30 },\n { name: 'Samantha', email: 'samantha@email.com', age: 31 },\n { name: 'Estefan\xc3\xada', email: 'estefan\xc3\xada@email.com', age: 16 },\n { name: 'Natasha', email: 'natasha@email.com', age: 54 },\n { name: 'Nicole', email: 'nicole@email.com', age: 43 },\n { name: 'Adrian', email: 'adrian@email.com', age: 21 }\n ];\nRun Code Online (Sandbox Code Playgroud)\n\n像这样更改 plunker,您将获得默认选择的值。
\n\n要设置视图上的默认值,您可以使用 ng-init 并将第一个对象设置为选定的
\n| 归档时间: |
|
| 查看次数: |
21846 次 |
| 最近记录: |