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
Post a Comment