[英]ng options select angular js
When I try to load options with an arrangement that has the format I leave you, the first option is blank and the following are the values of my arrangement. 当我尝试使用具有我离开的格式的安排加载选项时,第一个选项为空白,以下是我的安排的值。 That's a problem for me when I try to select one other option I can not get the value.
当我尝试选择其他选项时,这对我来说是个问题,我无法获取该值。
<select ng-model='form.type'
ng-options="item.name for item in organizations"
ng-change="update({{form.type.id}})">
</select>
Format : 格式:
{"status":0,"Area":[{"id":"1","name":"Marketing","private":null},{"id":"2","name":"Ventas","private":null},{"id":"5","name":"Soporte","private":null}],"Count":3}
Controller : 控制器:
$scope.organizations = data.Area;
What's happening in your case is that your ng-model
variable, which is form.type
, does not contain a value of your options in the select dropdown list. 您的情况是,您的
ng-model
变量form.type
不在选择下拉列表中包含选项的值。 That's why you see an empty row. 这就是为什么您看到一个空行。 If you want it to be, for instance, the first one, you can do this (I changed to
selected
variable, but it doesn't matter at all): 例如,如果您希望它成为第一个,则可以执行此操作(我将其更改为
selected
变量,但这一点都没有关系):
$scope.organizations = [{"id":"1","name":"Marketing","private":null},{"id":"2","name":"Ventas","private":null},{"id":"5","name":"Soporte","private":null}];
$scope.selected = $scope.organizations[0].id;
Now, the selected
variable has the id
of your option. 现在,
selected
变量具有您的选项的id
。 But that's not all. 但这还不是全部。 You also need to modify your HTML a bit, to have the
ng-options
have the id
as your value. 您还需要稍微修改HTML,以使
ng-options
的id
为您的值。 It can be anything you want in the object, not necessarily the id
, but that's why I assumed you needed, you can change it: 它可以是对象中您想要的任何内容,不一定是
id
,但这就是我假设您需要的原因,您可以更改它:
<select ng-model='selected' ng-options="item.id as item.name for item in organizations" ng-change="update({{selected}})">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.