javascript - 在 ng-click 上将元素从另一个 ng-repeat 推送到 ng-repeat

标签 javascript html angularjs angularjs-ng-repeat

我有两个 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/

相关文章:

html - 为什么webkit浏览器需要下载整个html5视频(mp4)才能播放?

javascript - 获取检查值 Ionic 3

css - 如何使用 CSS 样式 AngularJS 指令?

javascript - 如何在 Angular JS 条件下显示一个元素

javascript - ASP.NET Webform 中的 Javascript 问题

javascript - 带 Bootstrap 滚动 spy 的三级层次结构?

html - 图片在我的网站上出现锯齿状

javascript - jQuery:如何在出现滚动条时触发窗口调整大小事件

javascript - jquery load() 正在复制 div 层而不是重新填充内容

javascript - 事件监听器对于 ajax 驱动的 html 可以多次工作