aurelia 可绑定 object 属性 未在 json 中序列化
aurelia bindable object property not serialized in json
就像标题一样,我对组合的序列化有疑问object。
Class "Resort" 有两个 bindalbe 属性:Address 和 Manager。两者都没有被 httpClient.json 序列化,但如果删除 @bindable - 序列化工作完美。问题在哪里?
import {bindable} from 'aurelia-framework';
import {Address} from './../models/address.js'
import {Employee} from './../models/employee.js'
export class Resort {
id = "";
name="";
category_id = "";
organization_id = "";
manager_id = "";
owner_id = "";
active = "";
deleted = "";
date_created = "";
date_modified = "";
checkin = "";
checkout = "";
date_deleted = "";
notes = "";
address_id = "";
@bindable address = new Address();
@bindable manager = new Employee();
category_attraction = [];
category_option = [];
}
这是我的提取码:
this.http.fetch('resorts', {
method: 'post',
body: json(resortObject)
})
json 函数的结果:
{"id":"","name":"LOLO","category_id":"","organization_id":"","manager_id":"","owner_id":"","active":"","deleted":"","date_created":"","date_modified":"","checkin":"","checkout":"","date_deleted":"","notes":"","address_id":"","category_attraction":[],"category_option":[]}
TIA :)
我不知道你为什么会有这种行为,但你可以尝试使用 JSON.serialize(resortObject)
而不是 json(resortObject)
这是因为那些属性已经被封装为 属性 getter/setter 并且不再可枚举。
就像标题一样,我对组合的序列化有疑问object。
Class "Resort" 有两个 bindalbe 属性:Address 和 Manager。两者都没有被 httpClient.json 序列化,但如果删除 @bindable - 序列化工作完美。问题在哪里?
import {bindable} from 'aurelia-framework';
import {Address} from './../models/address.js'
import {Employee} from './../models/employee.js'
export class Resort {
id = "";
name="";
category_id = "";
organization_id = "";
manager_id = "";
owner_id = "";
active = "";
deleted = "";
date_created = "";
date_modified = "";
checkin = "";
checkout = "";
date_deleted = "";
notes = "";
address_id = "";
@bindable address = new Address();
@bindable manager = new Employee();
category_attraction = [];
category_option = [];
}
这是我的提取码:
this.http.fetch('resorts', {
method: 'post',
body: json(resortObject)
})
json 函数的结果:
{"id":"","name":"LOLO","category_id":"","organization_id":"","manager_id":"","owner_id":"","active":"","deleted":"","date_created":"","date_modified":"","checkin":"","checkout":"","date_deleted":"","notes":"","address_id":"","category_attraction":[],"category_option":[]}
TIA :)
我不知道你为什么会有这种行为,但你可以尝试使用 JSON.serialize(resortObject)
而不是 json(resortObject)
这是因为那些属性已经被封装为 属性 getter/setter 并且不再可枚举。