2012-07-22 44 views
0

在我的骨幹應用中,我有一個選擇菜單,它使用路由過濾列表中的一些員工,它由部門完成。根據路線URL設置選擇的值

E.g. 本地主機/#過濾器/ HR本地主機/#過濾器/在我看來,會計

routes: { 
    "filter/:type": "urlFilter" 
}, 

urlFilter: function (type) {  
    this.directory.filterType = type; 
    this.directory.trigger("change:filterType"); 
}, 

然後:

filterByType: function() { 
    if (this.filterType === "all") { 
     this.collection.reset(contacts); 
     app.navigate("filter/all"); 
    } else { 
     this.collection.reset(contacts, { silent: true }); 

     var filterType = this.filterType, 
      filtered = _.filter(this.collection.models, function (item) { 
       return item.get("type").toLowerCase() === filterType; 
      }); 

     this.collection.reset(filtered); 

     app.navigate("filter/" + filterType); 
    } 
}, 

不過,如果你訪問這些網址的直接選擇菜單中的一個不同步。

如何讓選擇與路線保持同步,其中選項選項值等於全部,人力資源和會計?

回答

0

將onchange處理程序添加到您的列表中,並相應地更新URL(通過添加當前列表項的參數值)。更改URL時防止重新加載頁面(谷歌爲它)。確保當您使用參數打開URL時(即在頁面加載時),當前列表項目會更新。