controller里面这样写的
$scope.interestes=[{
id:'0',
name:'通用兴趣'
},{
id:'1',
name:'通用兴趣1'
},{
id:'2',
name:'通用兴趣2'
},{
id:'3',
name:'通用兴趣3'
},{
id:'4',
name:'通用兴趣4'
},{
id:'5',
name:'通用兴趣5'
}]
$scope.interest=$scope.interestes[0].id;
我想通过id把name拿到
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
直接写
然后用 $scope.interest.name 去获取name不就是了
当数据源为数组时,ngOptions有以下传参方式。
其中select表示ngModel最后绑定的值,label则是表示选择在选择时显示的值。
话说根据id获取name不是直接可以在controller里面就能完成么。为什么要写个select。
jQuery.grep
楼主想要通过ID在
interestes获取name属性,除了迭代没有其它办法,上面是jQuery提供的工具函数,非常好用。