在ngrepeat内的ngopodel上的ngmodel

时间:2016-03-11 19:45:58

标签: javascript angularjs angularjs-ng-repeat ng-options

<p><b>Client Name</b></p>
<div ng-repeat="client in clientList">
  <b>{{client.name}}</b>
  <select value="Please select bot from list" ng-model='???' ng-options="b as b.name for b in listOfBots" |>
  </select>
</div>
<button ng-click="(getBotSelection())">Select Bots</button>

我找不到任何与此特定实现相关的文章。 clientList是一个来自excel文件的列表,告诉我更新客户端。我需要为该客户端运行一个机器人,所以我在listOfBots中将ng-options设置为bot.name。

我发现的文章的问题是它们通常不会迭代示例中的两个单独的集合。我很难用这个,请帮忙。

机器人列表看起来像这样

for (var i = 0; i < listOfBotsArr.length; i++) {
      listOfBotsObj.push({
        name: listOfBotsArr[i]
      });
      $scope.$apply();
  }

1 个答案:

答案 0 :(得分:0)

<div ng-show="showBotList">
  <p>You must select which bots to run manually</p>
  <p><b>Client Name</b></p>
  <div ng-repeat="client in clientList">


    <b>{{client.name}}</b>
    <select value="Please select bot from list" ng-model="bot" ng-options="b as b.name for b in listOfBots" ng-change="getSelectedBot(this.bot.name)" |>
    </select>
  </div>
  <button ng-click="">Select Bots</button>
</div>
这是我的解决方案。通过ng-change传递“this”并记录它,向我展示了我返回的对象,它有一个属性bot.name,所以我们有它。