简体   繁体   English

未从EmberJS中的组件发送操作

[英]Action not being sent from component in EmberJS

When I close a bootstrap modal, it doesn't send the action it should (in application js:) 当我关闭引导程序模式时,它不会发送应有的操作(在应用程序js中:)

application.hbs: application.hbs:

<li><a {{action "showSignInModal"}}>Sign In</a></li>
{{outlet}}
{{outlet 'modal'}}

bootstrap-modal.js: 引导-modal.js:

this.$('.modal').modal().on('hidden.bs.modal', function() {
  alert("Closed");
  this.sendAction('removeModal');
}.bind(this));

routes/application.js: 路线/ application.js中:

export default Ember.Route.extend({
  actions: {
    showSignInModal: function() {
      this.render('components.signin-modal', {
        into: 'application',
        outlet: 'modal'
      });
    },
    removeModal: function(){
      alert("Working")
    }
    //...
  }
})

signin-modal.hbs: 登入-modal.hbs:

{{#bootstrap-modal title="Sign In" ok='signin' okText="Signin"}}
<p>
  Please sign in. Thanks!
</p>
{{/bootstrap-modal}}

The "closed" alert shows, but the "working" alert doesn't. 显示“已关闭”警报,但不显示。 (The signin modal is a component, with no actions defined, and is just a bootstrap-modal) (登录模式是一个组件,未定义任何操作,而只是一个引导模式)

Actions won't propagate like event bubbing 动作不会像事件起泡那样传播

Wrap your bootstrap modal into a component and give it the removeModal action from the signin-modal to call. 将您的引导程序模式包装到组件中,并从signin-modal中给它执行removeModal操作以进行调用。

You are not passing your action name properly. 您没有正确传递动作名称。

You need to be aware that the sendAction method will fail silently if it can't find the action name. 您需要注意,如果sendAction方法找不到操作名称,它将以静默方式失败。

Make sure inside your template that contains the modal component, you pass a property with the action name you want to call: 确保在包含模态组件的模板内部,传递一个具有要调用的动作名称的属性:

{{#bootstrap-modal title="Sign In" ok='signin' okText="Signin" removeModal="removeModal"}}

You can read more about Passing Actions to Components 您可以阅读有关将动作传递给组件的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM