2013-03-09 80 views
2

The guide說,當一個動作被觸發時,Ember首先在當前控制器中查找一個處理程序,然後如果它在控制器中找不到它,它將查找當前路線,然後是父路線等。沒有看到發生。父路線不要求處理事件?

我的路線:

App.Router.map(function() { 
    // Creates 'products' and 'products.index' routes 
    this.resource('products', function(){ 
     // ... 
    }); 
}); 

我的超級瑣碎products.index模板;

<span {{action fooBar}}>Run fooBar</span> 

爲了測試這一點,目前我在/#/產品在瀏覽器和灰燼記錄「過渡到‘products.index’」說目前我在products.index如我所料,路線。現在,如果點擊的動作,灰燼應該尋找一個處理程序:

  1. ProductsIndexController
  2. ProductsIndexRoute
  3. ProductsRou​​te

我的意見:

  • 如果我把處理程序在ProductsIndexController中,它工作。
  • 如果我把處理程序放在ProductsIndexRoute中,它就可以工作。
  • 但是,如果我把處理程序ProductsRou​​te,它從來不叫:

App.ProductsRoute = Ember.Route.extend({ 
    events: { 
     fooBar: function(){ 
      alert("alarm!"); 
     } 
    } 
}); 

相反,我看到的錯誤:

*Error: Nothing handled the event 'fooBar'.* 

我缺少什麼?

+1

你可以創建一個[fiddle](http://jsfiddle.net/)來重現這種行爲,並且可能會打開[issue](https://github.com/emberjs/ember.js/issues)? – MilkyWayJoe 2013-03-09 02:07:17

回答

1

我的其他javascript文件之一還設置/創建App.ProductsRou​​te(並沒有採取任何行動),這是導致衝突。愚蠢的錯誤。