【问题标题】:Send actions to parent component?向父组件发送操作?
【发布时间】:2015-10-28 11:16:02
【问题描述】:

我有一个这样的模板:

{{#the-table}}
   {{#the-row selectedRow=selectedRow selectRow="selectRow"}}
     <td>something</td>
   {{/the-row}}
{{/the-table}}

当我点击 the-row 时,会触发一个动作 (selectRow)。
我希望the-table 接收操作,但它是接收器的父视图/组件。

如何改变这种行为?

【问题讨论】:

    标签: ember.js ember-cli


    【解决方案1】:

    在您的 the-table 中,您的 yield 语句应该产生 the-table 的上下文:{{yield this}}。然后您应该使用target 属性从the-row 定位表。

    {{#the-table as |table|}}
       {{#the-row selectedRow=selectedRow selectRow="selectRow" target=table}}
         <td>something</td>
       {{/the-row}}
    {{/the-table}}
    

    示例:http://emberjs.jsbin.com/pizilunaqi/edit?html,js,output

    【讨论】:

    • 谢谢,它确实有效,即使我从一个组件传递到另一个组件的项目还有其他问题......但我想这是一个不同的问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 2019-08-15
    • 2015-12-12
    相关资源
    最近更新 更多