fac*_*cot 5 angularjs angularjs-ng-options angularjs-ng-model
我的范围内有一个对象数组,我将它们列在下面的下拉控件中.
<select ng-model="selectedItem" ng-options="product.ID as product.Name for product in products">
<option value="">Please select a product...</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我还希望将selectedItem作为对象来获取对象的其他属性,以便我可以在页面中进行内容管理.例如;
<a ng-show="selectedItem.isAvailable">Buy Now!</a>
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个?谢谢.
您只需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>
Run Code Online (Sandbox Code Playgroud)
您当前的语法是select as label for value in array哪里select就是product.ID,让你只需将其更改为label for value in array
| 归档时间: |
|
| 查看次数: |
13967 次 |
| 最近记录: |