插入带有 javascript 的组件

Insert component with javascript

将 bootstrap 警报消息作为 ember 组件(它们显示成功错误警告消息...)。我如何在事件中插入消息?假设表单验证不成功,我想通过以下组件传递消息:

{{alert-mes message="The passwords must match" type="error"}}

Embner 有两种绑定方式,所以你不需要每次都传递不同的消息,相反你可以在控制器中有一个改变的属性,让你的组件监听变化:

// controller.js

showModal: false,
message: null,
actions: {
  somethingHapened: function() {
    this.set('message', 'The passwords must match');
    this.set('showModal', true);
  }
}

// template
{{alert-mes message=message type="error" show=showModal}}

// component

onShowModal: function() {
  if (this.get('show')) {
    // display the modal somehow
    // this.$().show(this.get('message'));
  } else {
    // hide the modal
  }
}.observes('show')