在一个ember应用程序中,我正在尝试返回与搜索词匹配且isActive等于true的记录。搜索部分有效,我无法让isActive真正与其余部分一起工作。
filterDecks(search) {
if (search.length < 2) {
return;
}
// keep it local™
search = search.toLowerCase();
let decks = this.store.peekAll('deck').filter(function(item) {
let title = (item.get('title') || '').toLowerCase();
let description = (item.get('description') || '').toLowerCase();
let tags = (item.get('tags') || []).toString().toLowerCase();
let isActive = (item.get('isActive'));
return title.includes(search) ||
description.includes(search) ||
tags.includes(search);
}, this);
this.set('filteredDecks', decks);
},
答案 0 :(得分:2)
您可以将isActive
条件与searchterm一起包含在内。
let decks = this.store.peekAll('deck').filter((item) => {
let title = (item.get('title') || '').toLowerCase();
let description = (item.get('description') || '').toLowerCase();
let tags = (item.get('tags') || []).toString().toLowerCase();
let isActive = (item.get('isActive'));
return ((title.includes(search) ||
description.includes(search) ||
tags.includes(search)) && isActive);
});
答案 1 :(得分:2)
您可以链接过滤器,并注意余烬filterBy
:
let decks = this.store.peekAll('deck').filter((item) => {
let title = (item.get('title') || '').toLowerCase();
let description = (item.get('description') || '').toLowerCase();
let tags = (item.get('tags') || []).toString().toLowerCase();
return title.includes(search) ||
description.includes(search) ||
tags.includes(search);
}).filterBy('isActive', true);