ngBuild在ngRepeat内部的ngoptions上

ngmodel on ngoptions inside ngrepeat

本文关键字:ngoptions 内部 ngRepeat ngBuild      更新时间:2023-09-26
<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 文件的列表,告诉我更新客户端。我需要为该客户端运行一个机器人,所以我将 ng 选项设置为在 listOfBots 中 bot.name。

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

机器人列表看起来像这样

for (var i = 0; i < listOfBotsArr.length; i++) {
      listOfBotsObj.push({
        name: listOfBotsArr[i]
      });
      $scope.$apply();
  }
<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,所以我们有了它。