ui-选择不按预期的绑定值

时间:2016-02-16 09:33:09

标签: angularjs ui-select ui-select2

将此选择框转换为多个选择框时出现问题。

 <select  style="width: 100%;" ng-model="vaccjobctrl.vacc.vaccination" 
                                     ng-options="vacctype.vaccinationId as vacctype.vaccinationName for vacctype in vaccjobctrl.vaccinationMast"
                                     class="form-control field-size ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" name="vaccinationName"
                                     id="vaccinationName" required >
                                     <option value="">--SELECT--</option>
                                     <option value="{{vacctype.vaccinationId}}">{{vacctype.vaccinationName}}</option>
                         </select>

尝试将此转换为多个选择ui,但未按预期返回

<ui-select tagging="tagTransform" ng-model="vm.user.instId" theme="bootstrap"  id="institute" name="institute"  append-to-body="false" ng-required="true">
                            <ui-select-match placeholder="Select Vaccination..."> <span
                                ng-bind="$select.selected.vaccinationName"></span> 
                            </ui-select-match> 
                                <ui-select-choices repeat="vaccine in (vaccjobctrl.vaccinationMast | filter: $select.search) track by vaccine.vaccinationId">

                            <span ng-bind="item.vaccinationName"></span> 
                            <!-- <div ng-bind-html="item.instName | highlight: $select.search"></div> --></ui-select-choices> </ui-select> 

这是存储在vaccjobctrl.vaccinationMast中的json。

{
  "code": 0,
  "message": "Total 6 records found",
  "result": [
    {
      "vaccinationId": 1,
      "vaccinationName": "vacc 1",
      "vaccinationNameAr": null
    },
    {
      "vaccinationId": 2,
      "vaccinationName": "vacc 2",
      "vaccinationNameAr": null
    },
    {
      "vaccinationId": 3,
      "vaccinationName": "vacc 3",
      "vaccinationNameAr": null
    },
    {
      "vaccinationId": 4,
      "vaccinationName": "vacc 4",
      "vaccinationNameAr": null
    },
    {
      "vaccinationId": 5,
      "vaccinationName": "vacc 5",
      "vaccinationNameAr": null
    },
    {
      "vaccinationId": 6,
      "vaccinationName": "vacc 6",
      "vaccinationNameAr": null
    }
  ]
}

小提琴http://jsfiddle.net/uhgvLjgp/44/

1 个答案:

答案 0 :(得分:0)

您没有在ng-options

中访问json中的结果数组
 ng-options="vacctype.vaccinationId as vacctype.vaccinationName for vacctype in vaccjobctrl.vaccinationMast.result"