Combine linkTo and action helpers in Ember.js

后端 未结 8 1881
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 13:50

I need to combine linkTo and action helpers in Ember.js. My code is:

{{#link-to \'index\'}}Clear{{/link-to}}


        
相关标签:
8条回答
  • 2020-12-13 14:50

    This works fine in 1.6.0-beta.5:

    <span {{action "someAction"}}>
      {{#link-to "some.route"}}
        Click Me
      {{/link-to}}
    </span>
    

    The link will happen and then the click will bubble up to the action handler. It's documented (albeit indirectly) here.

    Edit: corrected syntax in opening link tag

    0 讨论(0)
  • 2020-12-13 14:51

    Ember's link-to tags use routes to open new views, so you can perform whatever functionality you wanted to put in the link's 'action' attribute in the setupController method of the target route instead of in a controller action.

    See here in the Ember guide: http://emberjs.com/guides/routing/setting-up-a-controller/

    This only works if you want to perform the action every time the route is accessed, however, as opposed to with specific links.

    Make sure to include the controller.set('model', model); line along with whatever else you put in there.

    0 讨论(0)
提交回复
热议问题