如何区分ember.js中的动作按钮

时间:2014-04-16 12:00:36

标签: twitter-bootstrap ember.js

我正在为我的页面使用ember.js和bootstrap。

我的模态中有两个按钮,需要根据按钮的值进行两个不同的操作,例如批准操作和拒绝操作

<button type="button" class="btn btn-default" value="decline" {{action "pendingAction" selectedRow target="controller" }}>Decline</button>

<button type="button" class="btn btn-primary" value="approve" {{action "pendingAction" selectedRow target="controller"}}>Approve</button>

现在我想获得用户在控制器中点击的按钮的值

App.ApprovalrequestsController = Ember.ObjectController.extend({
  actions:{
    pendingAction:function(){

//get the clicked button value here,  so that i can do different tasks 
based on the value of button

  }
}
});

现在我想在控制器中的操作中获取单击的按钮值,以便我可以执行不同的任务..任何人都可以帮助我成为新手。

2 个答案:

答案 0 :(得分:2)

只需传入一个区分按钮的参数即可。你的新行动将是:

{{action "pendingAction" "decline" selectedRow target="controller" }}
{{action "pendingAction" "approve" selectedRow target="controller" }}

然后在你的处理程序中:

pendingAction: function(action, selectedRow) {
    switch(action) {
        case 'approve':
            // approve
            break;
        case 'decline':
            // decline
            break;
     }
}

答案 1 :(得分:0)

以下是示例http://jsbin.com/nasatupu/1/edit

您可以将参数添加到{{action}},如下所示:

<button type="button" class="btn btn-primary" value="approve" {{action "pendingAction"  "param1" selectedRow target="controller" value="approve" }}>Approve</button>