首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在AngularJS中显示下拉/选择选项中的多个值?

如何在AngularJS中显示下拉/选择选项中的多个值?
EN

Stack Overflow用户
提问于 2017-07-12 00:59:59
回答 1查看 41关注 0票数 1

我对AngularJS开发非常陌生,正在使用angularJS(Pre-2)。我有以下要求

客户列表的格式如下

代码语言:javascript
复制
{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选项中,我有以下内容

代码语言:javascript
复制
<select ng-model="customerID"
                ng-options="customer.customerID as customer.CustomerName +
        '  (' + customer.customerNumber + ')' for customer in customers">                
        </select>

我希望看到什么发生?

代码语言:javascript
复制
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?

我真的很感谢任何人在这方面的帮助。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-07-12 02:04:06

尝试下面的代码:

代码语言:javascript
复制
    <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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45040592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档