我有一个路径列表,可以包含通配符。筛选/突出显示包含通配符的匹配路径的最佳方法是什么?这样,当路径'/server/*‘f.ex时,路径'/server/test/block’将被标记。到目前为止,我已经尝试用.filter嵌套.contains,并检查数组是否大于1。然而,这只会给出精确的匹配,而且我没有找到一种很好的方法来向那些相互匹配的类添加相同的类。
为了运行该函数,我在mat单元格上测试了innerHTML选择器,但该函数多次运行。我还在mat单元格内的span上使用class.omeName-选择器进行了测试,但这也会多次调用函数。任何指点,我应该寻找的方向,将不胜感激。
使用材料表显示数据。
发布于 2018-11-21 11:20:25
最后,我向dataset添加了一个布尔值,“matchesPattern”。我找到了一个npm模块名为minimatch,它根据模式匹配与否提供布尔值。
import minimatch from 'minimatch';
markMatchingPaths() {
this.dataSource.data.map(p => p.matchesPattern = false);
const wildcards = this.currentDataSource.data.filter(w => w.path.includes('*'));
wildcards.forEach(w => {
this.dataSource.data.forEach(p => {
const res = minimatch(p.path, w.path);
if (res) {
p.matchesPattern = true;
}
});
});
}我在class.someName中使用了said布尔值,将类添加到环绕路径的span中。它们现在以不同的颜色突出显示。
https://stackoverflow.com/questions/53371901
复制相似问题