[Vuejs]-Vue,Js : Conditional search filter

0👍

Along the lines of this:

var test = {
  computed: {
    filteredRow: function() {
      return this.model.data.filter(row => {
        var value = row[this.query.search_column];
        switch (this.query.search_operator) {
          case "=": return value == this.query.search_input;
          case ">": return value > this.query.search_input;
          // ...
        }
      });
    }
  }
};

var vm = {
  model: {data: [{a: 1}, {a: 2}] },
  query: {search_column: "a", search_operator: ">", search_input: 1 }
};

console.log(test.computed.filteredRow.call(vm));

Missing: Type checks, type conversions, other operators, input sanitation.

Leave a comment