[英]Pass object into ng-model in selectbox
I have an selectbox that is filled with data from my backend. 我有一个选择框,里面装有来自后端的数据。 The data that comes from my backend Is an array with objects:
来自我后端的数据是一个包含对象的数组:
[Object { superkund_id="4", nod_id="12068", namn="Växjö Fagrabäck"}, Object { superkund_id="5", nod_id="9548", namn="Halmstad Bågen / Pilen"}]
I use ng-options to make the options In the select: 我使用ng-options来选择选项:
<td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item.superkund_id as item.namn for item in superkundOptions" ng-change="onChangeSuperCustomer(selectedSupercustomer)" ><option value=''>Select</option></select></td>
As you can see, I capture the the selected option with onChangeSuperCustomer: 如您所见,我使用onChangeSuperCustomer捕获了选定的选项:
$scope.onChangeSuperCustomer = function(selectedSupercustomer) {
//console.log(selectedSupercustomer);
}
The thing I want Is to pass the whole object that belongs to the selected option, so I can access all the properties that belongs to It. 我想要的是传递属于所选选项的整个对象,因此我可以访问属于它的所有属性。 How can I accomplish this?
我该怎么做?
更改您的ng-options以绑定整个对象item
,而不只是superkund_id
:
<td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item as item.namn for item in superkundOptions" ng-change="onChangeSuperCustomer(selectedSupercustomer)" ><option value=''>Select</option></select></td>
Simply by passing 'item' in 'onChangeSuperCustomer' method 只需在“ onChangeSuperCustomer”方法中传递“ item”
<select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item.superkund_id as item.namn for item in superkundOptions"
ng-change="onChangeSuperCustomer(item)" >
<option value=''>Select</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.