frontend/vue.js

vue.js: Multiple search

seul chan 2018. 6. 12. 21:19

vue filter with multiple object value.

...
computed: {
    filteredData: function() {
      let result = this.data;
      var search = this.search;
      var column_list = ['email', 'name']
      if (search) {
        // with ES5
        // result = result.filter(function (item) {
        //   return column_list.map(function (key) {
        //     return item[key].includes(search);
        //   }).includes(true);
        // });
        // ES6
        result = result.filter(item => column_list.map((key) => item[key].includes(this.search)).includes(true));
      }
      return result;
    },
},
...

And use it in html with v-for="data in filteredData".

'frontend > vue.js' 카테고리의 다른 글

vue.js: reset data  (0) 2018.06.11
Starting vue - vue 공식문서 정리 (~computed, watch)  (0) 2018.06.01
vue.js Router: vue-router  (0) 2018.01.30
vue.js: http via Vue Resource  (0) 2018.01.26
vue.js form 사용법  (0) 2018.01.23