以下代码将选项名称替换为 id。
<select ng-model="vm.ships" ng-change="vm.updateShip()" data-ng-options="ship as ship._id for ship in vm.readyships">
问:如何将名称设为“ship ship.id
is read (ship.to
)”?
这是否可以通过 ng-options 来实现?
想要的结果:
<option value="0" selected="selected" label="57e261">ship 57e261 is ready (sweden) </option>
更新:
变量ship.to
可用
最佳答案
您已经在 data-ng-options
的标签部分中执行了您想要的操作。为了获得完整的标签,您可以连接附加文本:
<select ng-model="vm.ships" ng-change="vm.updateShip()" data-ng-options="ship as ('ship' + ship._id + ' is ready (' + ship.to + ')') for ship in vm.readyships">
除了文档之外,此 previous answer总结了 ng-options
的不同选项。
关于javascript - 如何将选定的 ng-options 选项的名称更改为自定义名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40023886/