[英]Vue.js filter id on array
如何在 vue.js 上進行這樣的過濾?
$followid = [1,2,3,4,4,5];
foreach ($array as $element)
if (in_array($element->id, $followid))
endif
endforeach
您不應為此用例使用過濾器。 我不確定您是否可以在過濾器中訪問“this”。 我鼓勵您使用一個計算屬性來返回要顯示的數組。
computed: {
actifOnline: function() {
let self = this;
return this.online.filter((o) => {
return self.editlistAssesments.indexOf(o) > -1
}
}
}
您需要在過濾器中返回 bool :
ifInArray: function (value) {
return this.editlistAssesments.indexOf(value) > -1 ? true : false;
}
我最終在這個問題上試圖解決類似的問題,我想。
我使用了一種方法作為我的解決方案,我有一個用戶數組,我需要將當前登錄的用戶與我的模型上的管理器用戶數組相匹配:
methods: {
isManager( task, current_user ) {
return task.managers.find(x => x.id === current_user.id);
}
}
用法:
<button v-if="isManager(task, current_user)">Approve</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.