如何获得在VueJS使用滤波器阵列的特定元素(数组)?

时间:2019-01-30 10:17:53

标签: javascript vue.js

我试图获得一定的价值;例如,如果我得到了“2019”作为这个sort_id,我想元素包含“2019”作为sort_id 。所以我必须拿到2工作元素结果 进一步的问题)不从阵列滤波函数滤波器阵列或仅一个元件从阵列?

export default {
works : [
    {
        works_id: 'works1',
        sort_title: 'years',
        sort: '2019',
        title: 'etd1',
        year: '2019',
    },
    {
        works_id: 'works2',
        sort_title: 'years',
        sort: '2019',
        title: 'etd2',
        year: '2019',
    },
    {
        works_id: 'works3',
        sort_title: 'years',
        sort: '2018',
        title: 'etd1',
        year: '2018',
    }
 ]
}




<template>
 <div class="">
  <div v-for="(o, index) in getWorksImgs" :key="index">
   <div v-for="(a, index) in o" :key="index">
    <img :src="a.mother">
   </div>

 </div>
</div>

 <script>
 import StorageWorks from '@/storage/works'

export default {
name: 'Works',
 data() {
   return {
    workImgs : StorageWorks.works,
    sort_id : this.$route.params.sort_id
   }
 },
 computed: {
    getWorksImgs(){
        let worksImgs = this.worksImgs
        worksImgs= worksImgs.filter(w => w.sort === this.sort_id )

        return worksImgs

       }
    }
}
 </script>

1 个答案:

答案 0 :(得分:0)

以下代码将为您返回2张作品。

;WITH PD_All_ST_AND_PD_All_FT AS
(
     SELECT        DateAndTime, Millitm, TagIndex, Val
     FROM          PD_All_ST

     UNION

     SELECT        DateAndTime, Millitm, TagIndex, CAST(Val AS VARCHAR(50)) AS Val
     FROM          PD_All_FT
)
SELECT        DateAndTime, Millitm, TagIndex, Val
FROM          PD_All_ST_AND_PD_All_FT
WHERE         (DateAndTime = '2019-01-30 07:59:58.000') AND (Millitm = 597)

这里是根据条件过滤对象数组,而不是数组数组。