mardi 23 février 2016

Ember using computed property as an action parameter

I'm building an app to be used on iOS and desktop. I need to add the on="eventType" parameter to some actions, and use mouseUp for desktop and touchEnd for mobile. I can't seem to add both like on="eventOne eventTwo" so I tried doing it as a computed property, but it doesn't seem to work:

<a {{action 'selectTab' 'location' on=clickEvent}} class="{{if locationSelected 'active'}}"><span class="mi-person"></span></a>
<a {{action 'selectTab' 'portfolios' on=clickEvent}} class="{{if portfolioSelected 'active'}}"><span class="mi-movie"></span></a>


export default Ember.Component.extend({
    session: Ember.inject.service(),
    clickEvent: Ember.computed('session.isCordova', function() {
        return this.get('session.isCordova') ? 'touchEnd' : 'mouseUp';
    }),
    actions: {
        selectTab:function(tab){
            console.log("TAB SELCTED");
            alert("TAB SELCTED");
            this.set('selectedTab', tab);
        }
    }
}

My other option is to duplicate it with an if statement, but I'd rather have an




Aucun commentaire:

Enregistrer un commentaire