在下表中,我需要使用以下对象替换名称和类列中的值
+----------------+
| 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中实现此目的的有效方法是什么?
答案 0 :(得分: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]]));