2013-03-09 77 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(并没有采取任何行动),这是导致冲突。愚蠢的错误。