2015-06-27 39 views
0

我有一個顯示航班信息的應用程序。所有航班的全部列表可通過http://localhost:4200/flights以及法蘭克福航班的所有航班列表通過http://localhost:4200/flights?from=FRA刪除粘滯參數

下面顯示的列表是用戶在兩個視圖之間切換的兩個鏈接。不幸的是,一旦用戶點擊http://localhost:4200/flights?from=FRA鏈接,他/她無法通過點擊相應的鏈接回到http://localhost:4200/flightsfrom=FRA參數很粘。

如何鏈接到http://localhost:4200/flights頁面並擺脫from=FRA參數?

我使用的代碼:

應用程序/模板/ flights.hbs

<ul> 
{{#each flight in filteredFlights}} 
    <li>{{flight.code}} {{flight.from}} - {{flight.to}}</li> 
{{/each}} 
</ul> 

<ul> 
    <li>{{#link-to 'flights'}}All flights{{/link-to}}</li> 
    <li>{{#link-to 'flights' (query-params from="FRA")}}Flights from Frankfurt{{/link-to}}</li> 
</ul> 

應用程序/控制器/ flights.js

import Ember from 'ember'; 

export default Ember.Controller.extend({ 
    queryParams: ['from','to'], 
    from: null, 
    to: null, 

    filteredFromFlights: function() { 
    var from = this.get('from'); 
    var flights = this.get('model'); 

    if (from) { 
     return flights.filterBy('from', from); 
    } else { 
     return flights; 
    } 
    }.property('from', 'model'), 

    filteredFlights: function() { 
    var to = this.get('to'); 
    var flights = this.get('filteredFromFlights'); 

    if (to) { 
     return flights.filterBy('to', to); 
    } else { 
     return flights; 
    } 
    }.property('from', 'to', 'model') 
}); 

應用/路線S/flights.js

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    model: function() { 
    return this.store.find('flight'); 
    } 
}); 

回答

1

只是通過 '空':

{{#link-to 'flights' (query-params from='null')}}All flights{{/link-to}}