首页 > 解决方案 > 数组上的 Vue.js 过滤器 id

问题描述

如何在 vue.js 上进行这样的过滤?

$followid = [1,2,3,4,4,5];
foreach ($array as $element)
   if (in_array($element->id, $followid))
   endif
endforeach

标签: javascriptvue.js

解决方案


您不应该为此用例使用过滤器。我不确定您是否可以在过滤器中访问“this”。我鼓励您使用返回要显示的数组的计算属性。

computed: {
    actifOnline: function() {
        let self = this;
        return this.online.filter((o) => {
            return self.editlistAssesments.indexOf(o) > -1
        }
    }
}

推荐阅读