5

スコープにオブジェクト配列があり、以下のようにドロップダウン コントロールにリストします。

 <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>

誰でもこれで私を助けることができますか?ありがとうございました。

4

1 に答える 1

7

select asng-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

于 2014-09-22T12:25:03.073 に答える