在我的Angularjs项目中,我在ng-model
内使用ng-repeat
时遇到问题。当我在选择框中选择值时,选择框会自动选择前一个选定值。我认为这是由于ng-model
内的ng-repeat
<div ng-repeat="x in data">
<select class="selectbox_menulist" ng-change="endpoint.showEndPointStatsData()" ng-model="graphSelect.value">
<option ng-repeat="opt in mapOptions" value="{{opt.value}}">{{opt.type}}</option>
</select>
</div>
。我们如何解决这个问题呢?
HTML:
$scope.mapOptions = [
{ value: "bytes",type:"Bytes/sec" },
{ value: "packets",type:"Packets/sec"},
{ value: "megabytes",type:"Megabytes/sec"}
];
showEndPointStatsData: function() {
console.log('Function called ====');
console.log($scope.graphSelect.value);
JS:
List<String> newList = list.stream()
.map(x -> x.stream().collect(Collectors.joining(",")))
.collect(Collectors.toList());
newList.forEach(System.out::println);
}
答案 0 :(得分:1)
使用array
在ng-model
中存储mutli ng-repeat
的值:
<div ng-repeat="x in data track by $index">
<select class="selectbox_menulist" ng-change="endpoint.showEndPointStatsData($index)" ng-model="graphSelect[$index]">
<option ng-repeat="opt in mapOptions" value="{{opt.value}}">{{opt.type}}</option>
</select>
</div>
$scope.mapOptions = [{ value: "bytes",type:"Bytes/sec" }, { value: "packets",type:"Packets/sec"},{ value: "megabytes",type:"Megabytes/sec"}];
$scope.graphSelect = new Array($scope.data.length);
showEndPointStatsData: function(index) {
console.log('Function called ====');
console.log($scope.graphSelect[index]);
答案 1 :(得分:0)