组件没有动作处理程序...在ember 2.8.0和2.8.1之间的行为更改 [英] Component had no action handler for... Behaviour changes between ember 2.8.0 and 2.8.1

查看:148
本文介绍了组件没有动作处理程序...在ember 2.8.0和2.8.1之间的行为更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅这个 ember-twiddle

我想要的是向组件提供自定义按钮和自定义操作。该组件本身不知道所涉及的动作,这些动作有望向相应的控制器发起。

What I want is to provide custom buttons with custom actions to a component. The component itself does not know about the actions involved, these actions are expected to bubble to the corresponding controller.

此代码适用于ember 2.8.0,但不在当前版本(2.8.2)中。请使用旋钮在emberjs2.8.0和release之间切换。这是一个emberjs的错误吗?

This code works in ember 2.8.0 but not in the current release version (2.8.2). Please use the twiddle to change between emberjs "2.8.0" and "release". Is this an emberjs bug?

推荐答案

这在下一版本2.8.1中已经修复。
相关链接: https://github.com/emberjs/ember。 js / pull / 14291 / files

Yes it's Bug in ember version 2.8.0 alone. this has been fixed in next version 2.8.1. Related link : https://github.com/emberjs/ember.js/pull/14291/files

对于您的用例,我创建了旋转

For your use case, I created twiddle

有动作在应用程序控制器中,

Have actions in application controller,

import Ember from 'ember';
export default Ember.Controller.extend({
  appName: 'Ember Twiddle',
  actions:{
    buttonMethod(){
      console.log('buttonMethod');
    }
  }
});

创建我的按钮组件,以便它可以包含在任何组件中。这将调用从父组件传递的关闭操作。

Create my-button component so that it can be included in any of the component. this will call closure action which is passed from parent component.

my-button.hbs

<button {{action buttonMethod }}> ButtonComponent </button>
{{yield}}

创建 my-component 组件并发送关闭操作按钮方法到 my-button 组件。
my-component.hbs

{{my-button buttonMethod=buttonMethod }}
{{yield}}

application.hbs ,这是我们正在创建关闭操作的地方,在控制器中的 buttonMethod 操作。所以我们需要将这个 buttonMethod 属性一直传递给按钮组件。

In application.hbs, this is place we are creating closure action to buttonMethod action in controller. so we need to pass this buttonMethod property all the way down to button component.

{{my-component buttonMethod=(action 'buttonMethod') }}

这篇关于组件没有动作处理程序...在ember 2.8.0和2.8.1之间的行为更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆