2015-04-06 64 views
0

我有categories其中有許多products和一個窗體顯示下拉菜單。一旦Category被選中,Product下拉列表中的值將被過濾,以便只顯示屬於categoryproducts。這工作正常,直到用戶將selectedProduct下拉列表設置爲特定值。從控制器設置表格的值

我怎麼能重置selectedProduct下拉到All Products如果用戶點擊一個不同的Category他在Product點擊後?

應用/模板/ index.hbs

{{view "select" prompt="All Categories" 
       content=filteredCategories 
       optionLabelPath="content.name" 
       optionValuePath="content.name" 
       value=selectedCategory}} 

{{view "select" prompt="All Products" 
       content=filteredProducts 
       optionLabelPath="content.name" 
       optionValuePath="content.name" 
       value=selectedProduct}} 

回答

1

在您的觀察員在索引控制器selectedCategory,你需要有一個條件,看是否有selectedProduct已經存在。如果確實如此,那麼設置filteredProducts所有產品和selectedProduct爲「」:

if (this.get('selectedProduct')) { 
    this.set('filteredProducts', [<array of all products>]) && this.set('selectedProduct', ''); 
} 

不過,我有點困惑,爲什麼你想將其設置爲所有產品的陣列,當一個新的類別是選擇......你不是要根據新的類別設置filteredProducts到一系列產品嗎?

相關問題