【发布时间】:2020-04-01 06:54:57
【问题描述】:
我希望能够在对象中进行搜索、过滤和排序。下面是对象的代码。我有一个输入字段,可以在其中搜索对象。这也是我可以指示要搜索的内容+升序或降序的意图。
在图片中你可以看到 html 的样子。
这是搜索和排序的代码
const users = [{
id: 1,
name: "Jan",
age: 17,
city: "Dublin",
},
{
id: 2,
name: "Bob",
age: 17,
city: "London",
}
]
<form action="#" method="post" id="filters">
<label for="search">Search</label><input type="search" name="search" id="search" />
<label>Sort items by
<select id="sortby" name="sortby">
</select>
</label>
<select id="direction" name="direction">
<option value="asc">ascending</option>
<option value="desc">descending</option>
</select>
</form>
【问题讨论】:
-
我给你做了一个 sn-p 并引用了你的价值观
-
这能回答你的问题吗? Sorting object property by values
标签: javascript html sorting object filter