访问json对象数组中的数据以自动选择下拉列表中的值

时间:2016-05-06 23:06:46

标签: html angularjs json

如何通过与角度模型中的数据进行比较,从下拉列表中自动选择值。

json:

 {"EmployeeI9Docs":[
{"List":"","DocumentTypeId":7,"DocumentTitle":"Driver's license or ID card","DocumentIssuer":"DMV","DocumentNumber":"D998799","ExpirationDate":"2019-11-21T00:00:00"}
]
}

js file:

 EVerifyModule.controller('EVerifyI9Controller', ['$scope', '$http', 'EVerifyModuleI9Service',  function ($scope, $http, EVerifyModuleI9Service) {
    $scope.i9doctypes = [];

    //Get the employee Info
   EVerifyModuleI9Service.getEmployeeInformation(sessionStorage.ceId).then(function (response) {
        if (response != null) {
            alert(response.data.EmployeeInfo.DocumentTitle);
            $scope.employeeInfo = response.data.EmployeeInfo;   
        }
   });
    // Get the doc types (Lookup) for Dropdowns ListA, ListB, ListC.
   EVerifyModuleI9Service.GetI9DocTypes().then(function (response) {
       $scope.i9doctypes = response.data;
   });

}]);

HTML:

<div>
    <select name="ListA" class="form-control input-md"
            ng-disabled="selectedOptionB || selectedOptionC"
            ng-model="employeeInfo.EmployeeI9Docs[0].DocumentTitle"
            data-toggle="tooltip"
            data-original-title="{{selectedOptionA.description}}"
            ng-options="doc.brief for doc in i9doctypes | filter:{list:'A'} | orderBy:'index' track by doc.id">
     <option value=""> </option>
    </select>
</div>

1 个答案:

答案 0 :(得分:0)

需要改变两件事。 1. ng-model应该像

$scope.selectedEmployeeId;

  1. 将ng-options更改为:
  2. ng-options="doc.DocumentNumber as doc.DocumentNumber for doc in i9doctypes"