Vue.js中的按数字过滤

问题描述 投票:0回答:1

我是从头开始的。我有一个按商店名称过滤的输入,商店的名称是通过json收集的,其中也有id_store,但id_store是一个数字。我如何也可以按store_id进行过滤?

 computed: {
    filteredTiendas: function() {
      return Object.values(
        this.items
      ).filter(item => {
        return item.desc_store.match(this.search);
      });
    },
    searchUp: {
      get() {
        return this.search.toLowerCase();
      },
      set(search) {
        this.search = search.toUpperCase();
      }
    }
  }
};
[
{
"id_store": 2,
"desc_store": "ALBORAYA",
"type_store": "GSB"
},
{
"id_store": 4,
"desc_store": "LAS ROZAS",
"type_store": "GSB"
},
{
"id_store": 5,
"desc_store": "UTEBO",
"type_store": "GSB"
}
]
<div class="input-icon-wrap">
  <span class="input-icon"><img src="../../iconos/icon/[email protected]" alt=""></span>
  <input v-model="searchUp" placeholder="Busca tu tienda" class="input-with-icon" id="form-name">
</div>  
    </div>
    <div class="todastiendas">
    <div v-for="(item, i) in filteredTiendas" :key="i">
      <router-link :to="{name: 'secciones', params: { id: item.desc_store, id1: item.id_store  }}">
        <div class="tiendas">
            <span>{{item.id_store}}</span>
          <h1>{{ item.desc_store.toLowerCase()}}</h1>
          <img src="../../iconos/icon/chevron/[email protected]" alt />
        </div>
      </router-link>
    </div>
  </div>
json vue.js vuejs2
1个回答
0
投票

您可以更新filter()方法,例如:

.filter(item => {
   return item.desc_store.match(this.search) || item.id_store.toString().match(this.search);
});
© www.soinside.com 2019 - 2024. All rights reserved.