2014-11-22 94 views
1
<div class="ng_wrapper" 
data-ng-init="portfolios=[ 
{name: 'Portfolio 1', type: 'red'}, 
{name: 'Portfolio 2', type: 'red'}, 
{name: 'Portfolio 3', type: 'black'}, 
{name: 'Portfolio 4', type: 'black'} 
]">  
    <ul>    
     <li data-ng-repeat="portfolio in portfolios | filter:type "> 
     {{ portfolio.name | uppercase }} - [{{ portfolio.type | lowercase }}] 
     </li> 
    </ul> 
<select><option>red</option><option>black</option></select> 
</div> 

如何使用select進行'type'篩選?當我選擇紅色時,我只想顯示紅色投資組合。我怎樣才能做到這一點?通過angularjs中的選定選項過濾帖子

感謝

回答

1

您可以在ng-model屬性在filter添加到Drop-down,並參照同ng-repeat

<div class="ng_wrapper" data-ng-init="portfolios=[ 
{name: 'Portfolio 1', type: 'red'}, 
{name: 'Portfolio 2', type: 'red'}, 
{name: 'Portfolio 3', type: 'black'}, 
{name: 'Portfolio 4', type: 'black'} 
]"> 
    <ul> 
     <li data-ng-repeat="portfolio in portfolios | filter:portfolio_type "> 
     {{ portfolio.name | uppercase }} - [{{ portfolio.type | lowercase }}] 
     </li> 
    </ul> 
    <select ng-model="portfolio_type"> 
     <option>red</option> 
     <option>black</option> 
    </select> 
    </div> 

工作演示:http://plnkr.co/edit/5md1XYgNhrxWUWW8CwDc?p=preview

+0

阿西克,太感謝你了 – vol4ikman 2014-11-22 10:12:30

+0

歡迎您:) – Asik 2014-11-22 10:21:18

相關問題