将自定义参数从视图传递到控制器

时间:2015-05-22 17:19:08

标签: ember.js

我想将自定义属性(会话的ID)绑定到模板并从其控制器访问它,以便我可以将其传递给另一个控制器。我怎样才能做到这一点?我应该在哪里绑定它以及如何从控制器内部访问它?我应该与列表的视图进行交互,如果是这样的话?

模板:

<script type="text/x-handlebars" data-template-name="list">   
{{#each conv in model}}    
    <div class="conversation-content-wrapper" {{action "click"}}>
            <div class="history-message-assigned in-progress-closed" style="display:none;"><p><i class="icon-x"></i>Conversation closed</p></div>
            <div class="history-message-assigned in-progress-assignation" style="display:none;"><p><i class="icon-assign"></i>Conversation assigned</p></div>
            <div class="history-message-assigned in-progress-reopen" style="display:none;"><p><i class="icon-re-opened"></i>Conversation re-opened</p></div>          
        <div class="conversation-history">          
            <div class="conversation-time-history">{{{conv.timeAgoElement}}}</div>
            <div class="conversation-details">
                <span class="unread-numbers" data-badge="2"></span>
                    <input type="checkbox" name="conversations_ids[]" value="{{conv.id}}" />
                     <span class="conversation-name">{{conv.customer.name}}</span>
                     <span class="phone-number">{{conv.customer.cellPhoneNumber}}</span>
                    <p class="conversation-text">{{conv.lastMessage}}</p>
            </div>
        </div>                       
    </div>
{{/each}}     
</script>

控制器:

App.ListController = Ember.ArrayController.extend({

    needs: ['convcenter'],

    queryParams: ['status'],
    status : 'opened',

    actions: {

        click: function(){

        ** this is where I need to access the id property in convid**
        this.get('controllers.convcenter').set('selectedConv', 'convid')


    }

}

});

谢谢。

1 个答案:

答案 0 :(得分:0)

conv.id传递给行动

<div class="conversation-content-wrapper" {{action "click" conv.id}}>

将传递的id作为参数检索到action

actions: {
    click: function(convid) {
       this.get('controllers.convcenter').set('selectedConv', convid);
    }  
}