Reversing an array of content

I keep a list of lookups in my ArrayController. I would like the search terms to be displayed as the oldest. By default, Ember displays them in order.

You can see my current implementation here: http://andymatthews.net/code/emberTweets/

And here is the relevant code.

{{#each App.recentUsersArray.reverse}}
    <li>
        <a href="#" title="view again" {{action "searchAgain" target="App.recentUsersArray"}}>{{this}}</a>
    </li>
{{/each}}

App.recentUsersArray = Em.ArrayController.create({
    content: [],
    reverse: function(){
        return this.content.reverse();
    }.property(),
});

      

You can see that I am trying to change it using the property () method, but it doesn't work. Am I doing something wrong?

+3


source to share


1 answer


You should always use get

and set

to access properties. Also, if the computed property depends on others, you must add them to your declaration property

. Usage cacheable

may be dropped in next version of ember, see discussion . You can see a working example here .

reverse: function(){
    return this.get('content').toArray().reverse();
}.property('content.@each').cacheable()

      



You can also use method unshiftObject

on array and work around computed property creation, see http://jsfiddle.net/ez7bV/ .

+6


source







All Articles