我的范围中有一个对象数组,我将它们列在如下所示的下拉控件中。
<select ng-model="selectedItem" ng-options="product.ID as product.Name for product in products">
<option value="">Please select a product...</option>
</select>
我还希望将 selectedItem 作为一个对象来访问该对象的其他属性,以便我可以在我的页面中操作内容。例如;
<a ng-show="selectedItem.isAvailable">Buy Now!</a>
谁能帮我这个?谢谢你。
最佳答案
您只需要删除 select as
来自ng-options的部分,以便选中product
将是 ngModel,selectedItem
.
尝试:-
<select ng-model="selectedItem" ng-options="product.Name for product in products track by product.id">
<option value="">Please select a product...</option>
</select>
您当前的语法是
select as label for value in array
哪里select
是 product.ID
,因此您只需将其更改为 label for value in array
关于AngularJS ng-options 将所选项目作为对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25974045/