如何过滤包含给定字符串但也可能包含其他字符串的 airtable 记录?
How do you filter an airtable record that contains a given string, but may also contain others?
使用 airtable api 的 filterByFormula 方法,我可以查询 select 包含一个特定项目(字符串)的记录。但是,此查询仅 returns 仅包含该特定字符串的记录。
在此处搜索 airtable api 公式文档:
https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference
没有答案。
我有:
base('Table').select({
view: 'Main View',
filterByFormula: `Column = "${myFilter}"`
}).firstPage(function(err, records) {
if (err) { console.error(err); reject( err ); }
records.forEach(function(record) {
console.log(record.get('Another Column'));
});
同样,这个 returns 记录只有 myFilter,而不是在给定列中包含任何其他值的记录。
编辑:airtable 将这些列称为 'multiselect' 字段类型。
airtable 似乎以 SEARCH
的形式支持 indexOf
的 js 等价物。来自文档:
SEARCH(find_string, within_string, position)
Returns the index of the first occurrence of find_string in within_string, starting at position. Position is 0 by default.
因此,我们可以使用以下内容作为我们的搜索过滤器值
filterByFormula: `SEARCH("${myFilter}", Column) >= 0`
这将在我们的 Column
中搜索 myFilter
和 return 的任何结果 myFilter
位于 Column
中的某个位置。
注意:可能值得提醒的是,您的 myFilter
属性 可能最好至少有 2 个字符以提高性能。文档也没有指定不区分大小写的选项,因此如果您想要 return 结果,您可能希望将 Column
和 "${myFilter}"
包装在 LOWER()
函数中大写或小写字符。例如
filterByFormula: `SEARCH(LOWER("${myFilter}"), LOWER(Column)) >= 0`
使用 airtable api 的 filterByFormula 方法,我可以查询 select 包含一个特定项目(字符串)的记录。但是,此查询仅 returns 仅包含该特定字符串的记录。
在此处搜索 airtable api 公式文档: https://support.airtable.com/hc/en-us/articles/203255215-Formula-Field-Reference 没有答案。
我有:
base('Table').select({
view: 'Main View',
filterByFormula: `Column = "${myFilter}"`
}).firstPage(function(err, records) {
if (err) { console.error(err); reject( err ); }
records.forEach(function(record) {
console.log(record.get('Another Column'));
});
同样,这个 returns 记录只有 myFilter,而不是在给定列中包含任何其他值的记录。
编辑:airtable 将这些列称为 'multiselect' 字段类型。
airtable 似乎以 SEARCH
的形式支持 indexOf
的 js 等价物。来自文档:
SEARCH(find_string, within_string, position)
Returns the index of the first occurrence of find_string in within_string, starting at position. Position is 0 by default.
因此,我们可以使用以下内容作为我们的搜索过滤器值
filterByFormula: `SEARCH("${myFilter}", Column) >= 0`
这将在我们的 Column
中搜索 myFilter
和 return 的任何结果 myFilter
位于 Column
中的某个位置。
注意:可能值得提醒的是,您的 myFilter
属性 可能最好至少有 2 个字符以提高性能。文档也没有指定不区分大小写的选项,因此如果您想要 return 结果,您可能希望将 Column
和 "${myFilter}"
包装在 LOWER()
函数中大写或小写字符。例如
filterByFormula: `SEARCH(LOWER("${myFilter}"), LOWER(Column)) >= 0`