按字母顺序排序 immutable.js

Sorting by alphabetical order immutable.js

我想按 属性 name

对 immutable.js orderedList 进行排序

data.map(x => x.get("name")) returns 字符串,我想按名称字母顺序对我的地图进行排序。

怎么做?我试过了:

return data.sortBy((val) => {
    if (dir === "up") {
      return val.get("name");
    } else {
      return - val.get("name");
    }
  });
var fiends = Immutable.fromJS([{name: 'Squirrel'}, {name: 'Cat'}, {name: 'Raccoon'}]);
var sorted = fiends.sortBy(
  (f) => f.get('name')
);
sorted.map(x => x.get('name')).toJS();  // ["Cat", "Raccoon", "Squirrel"]

localCompare:

fiends.sort(
  (a, b) => a.get('name').localeCompare(b.get('name'))
);