对undefined属性的处理

This commit is contained in:
Xu Chang 2024-06-26 17:37:06 +08:00
parent a55005abe4
commit b9d58b84c2
2 changed files with 27 additions and 1 deletions

View File

@ -784,13 +784,22 @@ class ListNode extends Node {
*/
updateItem(lsn, data, id, action) {
// 如果数据键值是一个空字符串则更新成null
const undefinedAttrs = [];
// 如果数据键值是一个空字符串则更新成nullundefined则unset掉
for (const k in data) {
if (data[k] === '') {
Object.assign(data, {
[k]: null,
});
}
else if (data[k] === undefined) {
undefinedAttrs.push(k);
}
}
undefinedAttrs.forEach(
(attr) => unset(data, attr)
);
this.ulManager.push(lsn, {
action: action || 'update',
data,
@ -1210,6 +1219,7 @@ class SingleNode extends Node {
update(lsn, data, action) {
// 如果数据键值是一个空字符串则更新成null如果是undefined则取消此键值
const undefinedAttrs = [];
// 如果数据键值是一个空字符串则更新成nullundefined则unset掉
for (const k in data) {
if (data[k] === '') {
Object.assign(data, {
@ -1220,6 +1230,10 @@ class SingleNode extends Node {
undefinedAttrs.push(k);
}
}
undefinedAttrs.forEach(
(attr) => unset(data, attr)
);
this.ulManager.push(lsn, {
action: action || 'update',
data,

View File

@ -969,14 +969,22 @@ class ListNode<
id: string,
action?: ED[T]['Action']
) {
// 如果数据键值是一个空字符串则更新成null
const undefinedAttrs: string[] = [];
// 如果数据键值是一个空字符串则更新成nullundefined则unset掉
for (const k in data) {
if (data[k] === '') {
Object.assign(data, {
[k]: null,
});
}
else if (data[k] === undefined) {
undefinedAttrs.push(k);
}
}
undefinedAttrs.forEach(
(attr) => unset(data, attr)
);
this.ulManager.push(lsn, {
action: action || 'update',
data,
@ -1494,6 +1502,10 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
undefinedAttrs.push(k);
}
}
undefinedAttrs.forEach(
(attr) => unset(data, attr)
);
this.ulManager.push(lsn, {
action: action || 'update',
data,