0

在下表中,我需要使用以下对象替换名称和类列中的值

+----------------+
| id name  class |
+----------------+
| 1   a     x    |
| 2   b     y    |
| 3   a     z    |
+----------------+

name 
{
    a: "John",
    b: "Jill"
}

class
{
    x: "Maths",
    y: "Science",
    z: "Arts"
}

决赛桌应如下所示:

+----------------------+
|    id name  class    |
+----------------------+
| 1   John     Maths   |
| 2   Jill     Science |
| 3   John     Arts    |
+----------------------+

在 dexie.js 中实现这一目标的有效方法是什么?

4

1 回答 1

1

您将需要扫描整个表并一一替换行。

var map = {
  "name": {
    "a": "John",
    "b": "Jill"
  },
  "class": {
    "x": "Maths",
    "y": "Science",
    "z": "Arts"
  }
};

var db = new Dexie('yourdbname');
db.version(1).stores({
  yourTable: 'id'
});

db.yourTable.toCollection().modify(row => 
  Object.keys(map).forEach(column => row[column] = map[column][row[column]]));
于 2017-10-04T11:37:52.443 回答