javascript - 如何在javascript中过滤下拉菜单
问题描述
我有
const Fruits = [
{ name: "Apple", code: "1" },
{ name: "Orange", code: "2" },
{ name: "Mango", code: "3" },
{ name: "Derry", code: "4" }
];
const SelectedFruits=[]
如果用户从下拉列表中选择 Apple,我需要将其从 Fruits 中删除并将其添加到 SelectedFruits 中,如优先级明智,他可以更改它们,请帮助我,如果用户可以更改优先级,请再次帮助我。
解决方案
let searchData: { [key: string]: Object; }[] = [
{ Index: "s1", Country: "Alaska" }, { Index: "s2", Country: "California" },
{ Index: "s3", Country: "Florida" }, { Index: "s4", Country: "Georgia" }
];
let filter: DropDownList = new DropDownList({
dataSource: searchData,
// map the appropriate column
fields: { text: "Country", value: "Index" },
// set placeholder to DropDownList input element
placeholder:"Select a country",
// set true to allowFiltering for enable filtering supports
allowFiltering: true,
//Bind the filter event
filtering: function (e: FilteringEventArgs) {
let query = new Query();
//frame the query based on search string with filter type.
query = (e.text != "") ? query.where("Country", "startswith", e.text, true) : query;
//pass the filter data source, filter query to updateData method.
e.updateData(searchData, query);
}
});
filter.appendTo('#ddlelement');
你可以这样做。
推荐阅读
- angular - Angular 应用程序性能改进
- sql - Snowflake 无法合并具有相同数量的列和数据类型的两个查询
- jquery - 如何删除/替换输入的表情符号?
- google-bigquery - BigQuery - 获取叶行的递归查询
- arrays - 在表达式中使用时数组转换为指针
- linux - Unix find 命令以千兆字节显示文件大小
- rabbitmq - RabbitMQ 服务器配置为不同消费者服务多个同名队列
- java - 通过 Java 在单独的账户中从 lamba 调用 AWS lambda
- php - 在 Laravel 8.x 中循环嵌套注释
- reactjs - 使用反应路由器时,如何在 iframe 中使用反应应用程序提供静态 html 文件?