考虑到以下关系模式模式:
var Server = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: databases ,
relatedModel: Database ,
collectionType: DatabaseCollection ,
includeInJSON: id
}],
defaults: {
databases: []
},
});
var Database = Backbone.RelationalModel.extend({});
var DatabaseCollection = Backbone.Collection.extend({
model: Database
});
这些物体:
new Database({
id: 1,
name: DB1
});
new Database({
id: 2,
name: DB2
});
var s1 = new Server({
id: 3,
name: S1 ,
databases: [1,2]
});
将这种模式系列化或成型, 以何种最容易/最推荐的方式来质疑JSON的架构?
{
databases: [
{ id: 1, name: DB1 }
{ id: 2, name: DB2 }
],
servers: [
{ id: 3, name: S1 , databases: [1, 2] }
]
}
这样就可以将数据发送到 / 从服务器上读取 。
谢谢!
蒂姆·蒂姆