所以在标题中我对组合对象的序列化有疑问。
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:)
答案 0 :(得分:1)
这是因为这些属性已被包装为属性getter / setter并且不再可枚举。
答案 1 :(得分:0)
我不知道您为何会有这种行为,但您可以尝试使用JSON.serialize(resortObject)
代替json(resortObject)