【问题标题】:Getting values of multiple select inside one ng-repeat在一个 ng-repeat 中获取多项选择的值
【发布时间】:2015-05-01 07:24:07
【问题描述】:

我的一个 div 中有一个下拉列表,我从中选择要在第二个 div 中的下拉列表的数量。我的任务是能够从第二个 div 内的每个下拉列表中选择不同的值。这是我正在尝试的代码

<div ng-repeat="i in getNumber(secondN2.core.r1r2.value) track by $index">
                <div>
                    <strong><u>For Core link number {{$index+1}}:</u> </strong><br>
                        <strong>Select IM</strong>
                        <select ng-model="im" ng-change="calculate()" >
                            <option value="1 Gig" selected="selected">1 Gig</option>
                            <option value="10 Gig">10 Gig</option>
                        </select><br>

                </div>

</div>

secondN2.core.r1r2.value 是一个数字,我通过在 getNumber 方法中返回 new Array(n) 将其转换为数组,一个集合

在这种情况下如何给出正确的 ng-model ?以及如何检索这些值?

如果我尝试给i.im,它仍然没有帮助。随着im$scope.im 即将到来undefined

更新

什么是两个嵌套循环

<div ng-repeat="j in secondN3.core" style="border:1px solid;">
    <strong>Configure Core Links between {{j.name}}</strong><br><br>
            <div ng-repeat="i in getNumber(j.value) track by $index">
            <div>
                <strong><u>For Core link number {{$index+1}}:</u> </strong><br>
                <strong>Select IM</strong>
                <select ng-model="secondN3.coreValues[[$parent.$index,$index]]" ng-change="calculate()" >
                    <option value="1 Gig" selected="selected">1 Gig</option>
                    <option value="10 Gig">10 Gig</option>
                </select><br>
            </div>
        </div>
<div>

编辑:2

这行得通:This 是它的 plunker

【问题讨论】:

    标签: angularjs angularjs-ng-repeat angularjs-ng-model


    【解决方案1】:

    您的控制器中可以有一个数组来保存选定的值:

    $scope.values = [];
    

    然后将您的下拉列表绑定到此模型:

    <select ng-model="values[i]" ng-change="calculate()">
        <option value="1 Gig" selected="selected">1 Gig</option>
        <option value="10 Gig">10 Gig</option>
    </select>
    

    【讨论】:

    • 我做了ng-model="values[$index]",现在它正在工作:) 谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    相关资源
    最近更新 更多