我有两个 ng-repeat,我需要将值从一个 ng-repeat 添加到另一个,然后反之亦然,我的 html 如下所示:
<div id="external-events">
<div ng-repeat = "selected in selectedcolumn">
<div class="external-event bg-green" ng-mouseover="open = true" ng-mouseleave="open = false" > <i class="fa fa-question"></i>{{selected}}
<i class="pull-right fa fa-remove" type="button" ng-show="open" style="height: 5px;" ></i>
</div>
</div>
</div>
<div id="external-events">
<div ng-repeat = "item in columnnames">
<div class="external-event bg-yellow" ng-mouseover="open1 = true" ng-mouseleave="open1 = false" ><i class="fa fa-question"></i>{{item}}
<i class="pull-right fa fa-plus" type="button" ng-show="open1" ng-click="addSelectedColumn($index)" style="height: 5px;" ></i>
</div>
</div>
</div>
我现在唯一的想法是这样的:
$scope.columnnames=[
"brandname",
"category",
"type",
"description"
];
$scope.selectedcolumn=[
"memberID",
];
$scope.addSelectedColumn = function($index){
$scope.selectedcolumn.push($scope.columnnames.$index);
}
我怎么可能做到这一点?谢谢
最佳答案
试试这个
$scope.columnnames = [
"brandname",
"category",
"type",
"description"
];
$scope.selectedcolumn = [
"memberID",
];
$scope.addSelectedColumn = function ($index) {
$scope.selectedcolumn.push($scope.columnnames[$index]);
//$scope.apply() // uncomment if view is not updating
}
关于javascript - 在 ng-click 上将元素从另一个 ng-repeat 推送到 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48760280/