如何在AngularJS中显示DropDown / Select选项的多个值?

时间:2017-07-11 16:59:59

标签: select drop-down-menu

我是AngularJS开发的新手,正在使用angularJS(Pre-2)。我有以下要求

客户列表采用以下格式

{customerID: 100, customerNumber: 1002, CustomerName: "John DoeA"},
{customerID: 101, customerNumber: 1003, CustomerName: "John DoeB"},
{customerID: 102, customerNumber: 1004, CustomerName: "John DoeC"},

so, $scope.customers = customerList;

在选择选项中,我有以下

<select ng-model="customerID"
                ng-options="customer.customerID as customer.CustomerName +
        '  (' + customer.customerNumber + ')' for customer in customers">                
        </select>

我希望看到发生什么?

Once the user has selected one customer say, John DoeA, I would like display the entire customer information

Customer Number: 1002 (text box) Customer Name: John DoeA

How do I accomplish this one?

我非常感谢任何机构在这方面的帮助。

提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试下面的代码:     

    <p>Select a customer:</p>


    <select ng-model="selectedCustomer"
                    ng-options=" customer.CustomerName +
            '  (' + customer.customerNumber + ')' for customer in customers">                
            </select>
            </br>

    <h1>You selected:</h1>
    <span>CustomerID:</span>   {{selectedCustomer.customerID}} </br>
         <span>customerNumber:</span>   {{selectedCustomer.customerNumber}} </br>
         <span>CustomerName:</span>   {{selectedCustomer.customerID}} </br>

    </div>

    <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.customers = [
          {customerID: 100, customerNumber: 1002, CustomerName: "John DoeA"},
          {customerID: 101, customerNumber: 1003, CustomerName: "John DoeB"},
          {customerID: 102, customerNumber: 1004, CustomerName: "John DoeC"}
        ];
    });
    </script>