gpt4 book ai didi

javascript - ngRepeat 参数到 ngChange 函数

转载 作者:行者123 更新时间:2023-11-30 16:26:23 24 4
gpt4 key购买 nike

我试图将两个变量从 ngRepeat 传递给一个函数,但似乎我遗漏了什么。谁能解释一下这是什么?

<tr  ng-repeat="user in users"><td>
<select
ng-model="user.selection"
ng-options="action.id as action.name for action in userActions"
ng-change="actionChange(user.selection, user.id)"
required>
</select></td></tr>

$scope.actionChange = function(selection,id) {
$log.log(selection) // will display the selection
$log.log(id) // is undefined
}

最佳答案

你应该从 ng-options 返回 object

<select
ng-model="user.selection"
ng-options="action as action.name for action in userActions"
ng-change="actionChange(user)"
required>
</select>

您错过了将名称写入函数 & 并将该函数添加到作用域中。

$scope.actionChange =  function(user) {
$log.log(user.name) // will display the selection
$log.log(user.id) // is undefined
}

Demo Plunkr

关于javascript - ngRepeat 参数到 ngChange 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34090625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com