1

Hi every one i am going to build a real-estate application i want to add a condition in Bedrooms filter function like a "greater than equal "

Eg:- if i select 2 on Bedroom list i want to filter greater than equal 2 Bedrooms properties

How can i do this

export default {
  data() {
    return {
      blogs: [],
      minbed: this.$route.params.bed,
    }
  },
  created() {
    this.$http.get("https://test.json").then(function(data) {
      console.log(data);
      this.blogs = data.body;
    });
  },
  computed: {
    filteredList() {
      const { blogs, search, UnitType } = this;
      return this.blogs
        .filter(blog => blog.Bedrooms.includes(this.minbed))
  }
}
<select
  v-model="minbed"
  id="formInput202"
  class="form-control"
  value="MaxBedrooms"
>
  <option>Max.Bedrooms</option>
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
  <option>ST</option>
</select>
yqlim
  • 6,898
  • 3
  • 19
  • 43
Shamsheer Tp
  • 27
  • 10

1 Answers1

0

includes method is not working in this case. Only accepts string as the param (Ref-Link1).

The inline callback function will sort out this case,

Check the below code.

filteredList() {
    const { blogs, search, UnitType } = this;
    var MaxBedroomsVal = this.minbed;
    return this.blogs.filter( function (blog) { 
        return blog.Bedrooms >= MaxBedroomsVal;
    })
}

Ref: Link2

Tamilvanan
  • 708
  • 1
  • 7
  • 21