vue.js - sorting list of object by property in VueJS -


i have started learn vuejs 2 , more questions have harder becomes.

the idea have sample problem array of objects, want sort array "votes" property, can dynamically updated each separate element. want sort list votes dynamically. question how can without doing weird code.

in angular

for candidate in candidates | orderby: 'votes' 

but in here of though of like

v-for="(value, index, key) in sorted_candidates" 

where in .js i'll have

 computed : {       sorted_candidates() {           return this.candidates.sort((a, b) => { return b.votes - a.votes;});       }   } 

so question if there more elegant way solve problem? note: sorting on object property.

this simple enough solution, in vue1 can still use orderby in vue2 suggest opt current solution have, can reference on here


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -