下拉选择跟踪Id Angularjs
Drop down selection track by Id Angularjs
我有以下数据下拉在我的控制器。
$scope.groups={{"gpId": 3, "name" :"Tom"}, {"gpId": 32, "name" :"Helen"},{"gpId": 9, "name" :"Amy"}
$scope.user=
{
tkId: 32;
place: NW
}
在我的html中,我有以下选择
<select ng-model="user.tkId" ng-options="a.gpId as a.name for a in groups track by a.gpId></select>
当我运行这个,我得到下拉Helen选定,但当我想从下拉改变选择,它不让我。请让我知道我如何改变它来选择其他选项,这样我就可以保存它,如果需要的话。由于
下面的代码片段可以工作。
首先,对象数组写成如下[{}, {}]
在angular文档中写着track by
和as
不应该一起使用。
不要在同一个表达式中使用
select as
和track by
。它们不是一起工作的
<body ng-app="selectExample">
<script>
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.groups = [{
"gpId": 3,
"name": "Tom"
}, {
"gpId": 32,
"name": "Helen"
}, {
"gpId": 9,
"name": "Amy"
}];
$scope.user = {
tkId: 32,
place: 'NW'
};
}]);
</script>
<div ng-controller="ExampleController">
<label>Group:
<select ng-model="user.tkId" ng-options="group.gpId as group.name for group in groups"></select>
</label>
<br/> {{user.tkId}}
</div>
</body>
相关文章:
- 使用angularjs中的rest调用通过id获取数据
- AngularJS-工厂中promise ID字段的返回值
- AngularJS-点击对象,访问它's ID&以该ID作为参数激发函数
- 如何获得家长's的父's的父's id in Angularjs
- AngularJS - 如何从嵌套的ng-repeat将id传递给api
- Angularjs:如何检查元素的子元素是否包含某些元素(通过ID)
- Angularjs ng-show == Id?
- 在模板angularJs中从控制器填充id属性的值
- 如何使用表行id作为angularjs函数的参数
- AngularJS ex.com/forum?id=1 to ex.com/#/forum?id=1
- AngularJS如何在用户发送表单时放置数据和id
- 将html ID与angularJS一起使用
- 用angularjs将id从一页传递到另一页
- AngularJS通过匹配ID访问更多详细信息
- 如何在 AngularJS 中通过 id 访问 iframe
- 如何设置服务以传递谷歌工作表ID?AngularJS
- 基于 id Angularjs 过滤嵌套的 JSON 数据
- 通过id AngularJS设置焦点
- 下拉选择跟踪Id Angularjs
- 获取Bootstrap中按钮的属性ID;AngularJS