今天我有一个令人震惊的发现:在 View 上引用的操作是由它们的路由处理的,而不是由引用它的 View 处理。前任:

<a href="#" {{action edit}}>Edit this</a>
edit Action 必须在 Route 中定义,而不是在 View 中。在 View 负责处理此类事件之前我不使用路由器时,我对此感到非常高兴。

任何人都可以请:
  • 向我解释为什么 Route 必须处理事件,以及这个
  • 的好处是什么
  • 告诉我如何在处理此类操作/事件时将控制权交还给 View?
  • 最佳答案

    将目标设置为 View

    <a href="#" {{action edit target="view"}}>Edit this</a>
    

    如果您的操作在 Controller 中,则使用
    <a href="#" {{action edit}}>Edit this</a>
    

    默认目标是指 View 的 Controller

    我建议你通过这个引用:Ember Action Helper

    我想根据上述引用提及一些关键点
  • 在一个典型的 Ember.Router 支持的应用程序中, View 通过使用 {{outlet}} 助手来管理, Action 将被转发到当前 Controller 。

  • 如果 Controller 中没有定义 Action ,则当前路由是目标。
  • 关于view - EmberJS : How to handle actions from the View not the Route/Controller,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13178441/

    10-11 15:27
    查看更多