getCleanSerializableObject 获取非空的普通对象数据
2025/4/16小于 1 分钟
getCleanSerializableObject 获取非空的普通对象数据
说明
获取可以被序列化的 json 对象,但是会自动去除:''、[]、{}
案例
案例一
模型
class Test extends ModelBase {
@Column()
public str?: string
@Column()
public emptyStr?: string
@Column({})
public arr?: any[]
@Column({})
public emptyArr?: any[]
}
实例初始化
const test = new Test({
str: 'str',
emptyStr: '',
arr: [123, '', [], {}],
emptyArr: [],
})
打印日志
console.log(test.getCleanSerializableObject())
// { str: "str", arr: [123, "", [], {}] }