我有一个使用 Javascript 和 VueJS 框架的应用程序。我正在尝试创建根据用户类型过滤的项目的“下拉列表”。
以下是如何在页面上呈现列表的代码:
<div>
<v-list v-for="item in userInputedFormulas" :key="item.id" >
<v-list-item>
<v-list-item-title>
{{ item.name }} {{ item.structure }}
</v-list-item-title>
</v-list-item>
</v-list>
</div>
下面是 userInputedFormulas 的生成方法:
userInputedFormulas() {
this.userInput.forEach(element => {
if(this.allFormulas?.filter(formula => formula.name.includes(element.toLowerCase()))) {
filteredList = this.allFormulas?.filter(
formula => formula.name.includes(this.userInput)
);
} if(this.userInput == this.allFormulas?.filter(formula => formula.name)) {
filteredList = this.allFormulas?.filter(formula => formula.name = this.userInput)
}
});
return filteredList;
}
请注意,allFormulas 基本上返回所有公式的对象数组,例如 [{name: 'SUM', structure: 'blah'},{name: 'ADD', structure: 'blah'},{name: 'MINUS', structure :'废话'}]
从某种意义上说,它在用户键入时过滤“公式”列表,就像这样:
但是,当用户输入字符( - 圆括号 - 我想过滤它以便它只显示确切的公式。
例如,用户键入“SUM(”,而不是上面的图片,它显示名称中包含“SUM”的所有项目,它应该只显示“SUM”项目。我怎么能过滤这个,因为我不确定如何走得更远?
