从下拉列表中获取旧值和新值 [英] Get old value and new value from dropdown

查看:44
本文介绍了从下拉列表中获取旧值和新值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to simply get the previous value, and the newly selected value from a drop-down. In this example, the drop-down is pre-populated with the current group the user is assigned.

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

When the drop-down is changed, I want to be able to return the old value and the new value. I can already get the old value, but I don't know how to return the new value.

控制器代码:

// 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>

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

I've created a fiddle here using the watch example that was provided in the first response below. 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);
}

这篇关于从下拉列表中获取旧值和新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆