AngularJS ng-options将选定项目作为对象
发布时间:2020-12-17 17:45:35 所属栏目:安全 来源:网络整理
导读:我的范围内有一个对象数组,我将它们列在下面的下拉控件中. select ng-model="selectedItem" ng-options="product.ID as product.Name for product in products" option value=""Please select a product.../option /select 我还希望将selectedItem作为对象来
我的范围内有一个对象数组,我将它们列在下面的下拉控件中.
<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> 谁能帮我这个?谢谢. 解决方法
您只需要从ng-options中删除select作为部分,以便所选产品将是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是product.ID,因此您只需将其更改为数组中值的标签 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |