我是AngularJS的新手。我正在編寫下拉菜單的代碼。每行都有相同的下拉列表。這是代碼AngularJS:多個下拉列表
HTML:
<tr ng-repeat='item in items>
<td>
<span>{{item.profName}}</span>
<span ng-if="!item.editProf">
<img src="images/img1.png" class="img"
ng-click="editProf({{item.pId}})"></img>
</span>
<div ng-if="item.editProf">
<select ng-model="prof" class="form-control" name= "profName"
ng-options="prof.name as prof.value for prof in lookups.prof"
ng-Blur="updateProf([item.pId])">
</select>
</div>
</td>
</tr>
腳本:
$scope.editProf = function(pId)
{
var profIndex = $scope.profIndexList[pId];
var profObj = $scope.profList[profIndex];
profObj.editProf = true;
$scope.prof = profObj.profName;
}
當我在圖像上單擊它會去到編輯模式。當我選擇一個選項時,它將再次進入只讀模式。但是,當我打開兩個下拉菜單時,它會爲兩個下拉菜單顯示相同的選項(當我從第二個下拉菜單中選擇一個選項時,由於範圍相同,同一個選項會在第一個下拉菜單中更新)。如何解決這個問題? 幫幫我。
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', ['$scope',
function($scope) {
$scope.cols = [{
col_id: 'test1',
col_name: 'First'
}, {
col_id: 'test2',
col_name: 'Second'
}];
$scope.col = "test1";
}
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<select
ng-options="col.col_id as col.col_name for col in cols"
ng-model="col">
</select>
<select
ng-options="col.col_id as col.col_name for col in cols"
ng-model="col">
</select>
</div>
的jsfiddle:http://jsfiddle.net/x8rq2pda/23/
您在示例代碼中看到2個選擇嗎? – sirrocco
第二個下拉菜單在哪裏?請提供完整的代碼示例。 – sdgluck
好吧,他們顯然有相同的選擇,因爲他們都使用'ng-model =「prof」'綁定到'prof'。您需要將每個選擇綁定到不同的模型。類似於'ng-model =「item.prof」' –