emberjs: how to trigger a custom event in a View

后端 未结 1 561
我寻月下人不归
我寻月下人不归 2021-01-28 03:16

I would like to turn a primitive event (a click) into a semantic event, like \"deleteTodo\" This is described here, but not how to implement :(
I have the following code:

相关标签:
1条回答
  • 2021-01-28 03:55

    You can use this.get("controller").send("deleteTodo"). This will send a message to the controller, if the controller doesn't handle deleteTodo it will bubble to the router and be handled there.

    click: function(e) {
        this.get('controller').send("deleteTodo");
    }
    

    In your router you will also need to define the event:

    events: {
      doStuff: function(e) {
        alert("Do stuff") ;    
      }
    }
    

    http://jsfiddle.net/9Xasr/7/

    I would typically do record deletion in the controller. Seems like putting that in a router event would not be ideal.

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