2015-04-06 66 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到一系列产品吗?

相关问题