簡體   English   中英

角度ng-repeat內的嵌套ng-option

[英]Nested ng-option inside angular ng-repeat

我目前正在嘗試將<select>嵌套在具有ng-repeatdiv

像這樣的東西:

       <li ng-repeat="item in items >
            <div class="row">
                <div class="col-xs-7">
                    <span ng-bind="item.Name"></span>
                </div>
                <div class="col-xs-4 modal-body--ul--li__dropdown_container">
                    <select ng-model="typemodel" >
                        <option ng-repeat="usertype in item.userGroups"></option>
                    </select>
                </div>
                <div class="col-xs-1">
                    <a ng-click="add(item)"></a>
                </div>
            </div>
        </li>

在控制器中,我將該項目添加到具有選定項目的新列表中。 我還想將下拉列表中的值作為新值添加到控制器中的列表中。

$scope.add = function (item) {

    //New value with the value from the dropdown
    item.recipientType = typemodel;
    $scope.selected.push(item);
};

名單 :

$scope.items = [  
     {           
        "Name":"Name1",
        "userGroups":[
            { "type": "gruop1" },
            { "type": "gruop2" },
            { "type": "group3" }            
        ]
     },
     {  
        "Name":"Name2",
        "userGroups":[
            { "type": "gruop1" },
            { "type": "gruop2" },
            { "type": "group3" }            
        ]
     }
    ]

簡而言之,當我點擊“添加”時,我需要從下拉列表中選擇當前類型模型的值。

這是現在的樣子,但是不起作用。 我知道我必須獲得正確的模型,並可能通過$ index跟蹤項目列表,但是整天在網上搜索解決方案后,即時消息仍然卡住了!

感謝所有幫助。

-謝謝!

PS。 如果問題中缺少某些內容,或者需要更多解決方法,請發表評論。

首先,將下拉列表更改為

<select ng-options="usertype in item.userGroups" ng-model="item.recipientType">

然后,當您觸發添加功能時,項目的屬性recipientType類型已經設置。

$scope.add = function (item) {
    console.log(item.recipientType);
    $scope.selected.push(item);
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM