I'm building an Ember app that needs to fade out a background DIV when a form input becomes focused.
I have defined actions on my Application route, and set a property in my model (because I'm trying to do this without a controller, like the Ember 2.0 way). I'm trying to do Action Up, Data Down. I have the actions going up to the Application route, but the data just isn't making it back down to the component.
I have the actions bubbling up to the application route just fine, but when I update the property re.sub('\[(.*?)\]', '', s)
it never makes it back down to the component.
I have this fading out background image on every route of my site, so moving all the actions to each route seems like a lot of code duplication.
What am I doing wrong?
this.controllerFor('application').set('showBackground', true);
Is this the correct way to replace "properties" and controllers with routes? All the "move to Ember 2.0" advice I can find doesn't mention how to replace high level properties.
EDIT I created a JSbin, but I'm not sure if it's setup correctly for the 2.0 style (no controllers), as the import/export (ES6?) stuff doesn't work on JSbin.
http://emberjs.jsbin.com/wunalohona/1/edit?html,js,console,output
I couldn't actually get any of the actions to bubble correctly.
答案 0 :(得分:3)
您提供的jsbin存在多个问题。以下是我修复的一些问题。
您需要在App命名空间中指定路由,组件或Ember将无法找到它。 ember-cli中使用的解析器是自定义的。
var ApplicationRoute = Ember.Route.extend({
应该是App.ApplicationRoute = Ember.Route.extend({
var BackgroundImage = Ember.Component.extend({
应该是App.BackgroundImageComponent = Em.Component.extend({
您无需在路线中指定setupController
方法。默认情况下,从模型钩子返回的模型设置为控制器的模型属性。
https://github.com/emberjs/ember.js/blob/v1.11.1/packages/ember-routing/lib/system/route.js#L1543
不推荐使用ObjectController和ObjectController的代理行为。
现在通过添加model.
+ modelPropertyName来引用模型属性
You can read more about this in the deprecation page for v1.11
action
应为actions