1

I want to display a sorted list using the value I get from my DataObject:

<div class="recommendation" v-for="l in list" :key="`_${l.id}`">

My list is not currently ordered:

export default {
  name: "HelloWorld",
  data() {
    return {
      list: []
    };
  },
  mounted: function() {
    let self = this;
    backend.matches().then(function(resp) {
      self.list = resp.data.listings;
    });
  },
  computed: {
    
  }
};

I want to order my list with my l.weight value in descending order.

What would be the best approach to order my list?

1 Answer 1

2

Try to use the sort method :

    backend.matches().then(function(resp) {
      self.list = resp.data.listings;
      self.list.sort((a,b)=>a.weight<b.weight?1:-1) 
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.