twitter-bootstrap - 当将值作为参数传递给 addin 时将值传递给 ember.js 组件(例如 ember-bootstrap-modals-manager)

标签 twitter-bootstrap ember.js modal-dialog web-component

我对插件有疑问 ember-bootstrap-modals-manager但其他 Ember 插件也可能会出现我所描述的问题。

使用 ember-bootstrap-modals-manager 您可以显示 alert dialogcustom body 。这是示例的屏幕转储。

enter image description here

为此,您需要创建一个 Ember 组件,其模板包含您的自定义正文标记,例如...

<p class="alert alert-info">
  Custom Alert Body Component
</p>

...然后,您可以通过在调用警报对话框时指定组件的名称来指定警报正文应使用该标记,如下所示(假设创建的组件称为 custom-alert-body ) ...

showCustomAlertModal() {
    const options = {
      bodyComponent: 'custom-alert-body',
    };
    set(this, 'options', options);
    get(this, 'modalsManager')
      .alert(options);
 }

...这很好,但如果您想将值注入(inject)组件模板,例如像这样...

<p class="alert alert-info">
  Custom Alert Body Component. The alert msg is : {{alertmsg}}
</p>

...如何做到这一点并不明显,因为与“正常”组件使用不同,您不是在模板中调用相关组件,而只是在代码中指定名称。

所以我的问题是(如果您熟悉 ember-bootstrap-modals-manager)您如何拥有一个在运行时接受值的自定义主体,或者(如果您不熟悉它)您见过在不同的上下文中像这样使用的组件,如果是的话,它们如何接受运行时值?

最佳答案

是的,你说得对。由于组件 bodyComponent 不是由您直接通过模板调用,而是通过动态 {{component}} 帮助程序调用,因此包 ember-bootstrap-modals -manager 应该公开一种将值传递到组件的方法。

查看了包的源代码并发现 options object has been sent到动态调用的组件。因此,您可以通过选项对象发送 alertMsg:

showCustomAlertModal() {
    const options = {
      bodyComponent: 'custom-alert-body',
      alertMsg: 'Post created successfully' // <- your alert message
    };
    set(this, 'options', options);
    get(this, 'modalsManager')
      .alert(options);
 }

并且可以通过选项参数访问:

<p class="alert alert-info">
  Custom Alert Body Component. The alert msg is : {{options.alertmsg}}
</p>

但是,浏览文档时,这一点并不明显。当您有时间时,您甚至可以为文档做出贡献:)

关于twitter-bootstrap - 当将值作为参数传递给 addin 时将值传递给 ember.js 组件(例如 ember-bootstrap-modals-manager),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60346921/

相关文章:

jquery - 如何打开 jQuery 模式与元素一样宽但不更宽?

javascript - 过滤数据后打开模态 Bootstrap

javascript - Bootstrap 修复了带有/视差滚动问题的导航栏

html - 具有可变高度的 Bootstrap div

ember.js - 在 Ember CLI 中使用 pod 结构有什么限制吗?

javascript - 对话框打开后停止加载页面

javascript - 表单提交后,Bootstrap 选项卡会转到同一页面上的特定选项卡

javascript - Ember .get 未返回正确的值

ember.js - 为什么这个 Ember.js 应用程序在 Firefox 中失败?

javascript - Material-UI 仅包含某些组件