gpt4 book ai didi

angularjs - 从下拉列表中获取旧值和新值

转载 作者:行者123 更新时间:2023-12-03 22:25:56 25 4
gpt4 key购买 nike

我试图简单地获取以前的值,以及从下拉列表中新选择的值。在此示例中,下拉列表预先填充了用户分配的当前组。

当下拉列表更改时,我希望能够返回旧值和新值。我已经可以获得旧值,但我不知道如何返回新值。

Controller 代码:

// User Object
userAccess = [{"user_name":"dodsosr11",
"group_level":1,
"user_id":500,
"group_id":10,
"group_name":"Conferences_Admins"},
{"user_name":"keatikj09",
"group_level":1,
"user_id":250,
"group_id":10,
"group_name":"Conferences_Admins"},
{"user_name":"malinag10",
"group_level":1,
"user_id":492,
"group_id":10,
"group_name":"Conferences_Admins"}];

//Group Object
groupAccess = [{"group_name":"Conferences_Admins",
"id":10,
"level_id":1},
{"group_name":"ticket_sales",
"id":59,
"level_id":3},
{"group_name":"Web Developers",
"id":1,
"level_id":1}];


$scope.reassignUser = function(){
var oldGroup = this.user.group_id;
var newGroup = ?????

};

HTML:
<tr ng-repeat="user in userAccess">
<td>{{ user.user_name}}</td>
<td>
<select ng-change="reassignUser()"
ng-model="user.group_name"
ng-options="g.group_name as g.group_name for g in groupAccess">
</select>
</td>
</tr>

我在这里使用下面第一个响应中提供的 watch 示例创建了一个 fiddle 。 http://jsfiddle.net/LHz9D/1/

最佳答案

像这样尝试

查看

<select ng-model="selected" ng-change="change(selected, {{selected}})">

JS
$scope.change = function(newObj, oldObj){
console.log(newObj);
console.log(oldObj);
}

关于angularjs - 从下拉列表中获取旧值和新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909163/

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