【问题标题】:Get id of selected item in ng-option获取 ng-option 中所选项目的 id
【发布时间】:2016-05-27 13:51:02
【问题描述】:

我想获取所选项目的 id,但 console.log 显示 undefined

查看

 <select ng-change="test()" ng-model="selectedone" ng-options="item.id as item.pseudo for item in friends"></select>

控制器

  $scope.test = function(){
        console.log($scope.selectedone);
    }

【问题讨论】:

  • 我不知道你做错了什么,OP。它对我有用。见小提琴:jsfiddle.net/Lvh8djp2
  • 我正在使用 ionic 我不知道这是否重要
  • 您的代码 sn-p 为我工作,也许您的数组格式错误?你能用小提琴来证明你的问题吗?
  • 我设法解决了这个问题,请看我的回答

标签: angularjs angular-ngmodel ng-options


【解决方案1】:

下面是运行代码:

查看:

 <select ng-change="test(selectedId)" ng-model="selectedId" ng-options="id.id as id.pseudo for id in idList"> </select>

控制器:

  $scope.test = function(selectedId) {
            alert(selectedId);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2020-07-14
    相关资源
    最近更新 更多