function sort(type) {
$("#parentDiv").empty();
$.getJSON("raw_data.json", ({ Search }) => {
Search.sort((a, b) => a[type] > b[type]);
console.log(`Sorted by: ${type}`);
...code
在不同的浏览器中显示不同的结果,但正确的结果显示在firefox devoloper版本中,错误的结果显示在chrome浏览器中。
答案 0 :(得分:0)
sort函数应返回一个数字
小于0的数字会将元素A移动到比B
更低的索引大于0的数字会将元素B移动到比A
更低的索引如果数字为零,则会将元素保留在同一位置。
有关此处排序功能的更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort