我在ember中有一个模型,部分看起来像这样:
opt1votes: DS.hasMany('subscriber'),
opt2votes: DS.hasMany('subscriber'),
opt3votes: DS.hasMany('subscriber'),
opt4votes: DS.hasMany('subscriber'),
opt5votes: DS.hasMany('subscriber'),
keyword: DS.belongsTo('keyword'),
winAttachment: DS.belongsTo('asset'),
followAttachment: DS.belongsTo('asset'),
attachment: DS.belongsTo('asset'),
如果此模型没有将id分配给winAttachment,followAttachment和附件属性(这些在系统中是可选的),则会出现此问题。而不是没有为这些属性加载任何东西,ember正在接触我们的api并获得此响应:
{"asset":[]}
这导致3"资产"使用" undefined"创建的模型作为所有属性:http://screencloud.net/v/nZDD
我的问题是为什么没有id的ember加载以及如何停止?我应该为空模型请求返回不同的内容,以便ember知道模型是不完整的吗?
感谢所有帮助!
编辑:来自对象的原始JSON:
{
"campaign": [
{
"id": 360,
"name": "aa test",
"message": "Thanks",
"followMessage": "",
"followTime": "",
"opt1": "",
"opt2": "",
"opt3": "",
"opt4": "",
"opt5": "",
"opt1votes": [],
"opt2votes": [],
"opt3votes": [],
"opt4votes": [],
"opt5votes": [],
"singleEntry": false,
"winnerNumber": "",
"winningMessage": "",
"winners": [],
"tagIds": "",
"campaignType": "Response",
"starred": false,
"draft": false,
"completed": false,
"archived": false,
"optins": 0,
"optouts": 0,
"keyword": 352,
"paused": false,
"startDate": 1396475400,
"startDateDisplay": "Apr 02, 2014 4:50PM",
"percentComplete": 0,
"created": "Wednesday, Apr 2 2014 4:49PM",
"attachment": "",
"followAttachment": "",
"winAttachment": "",
"entryQuota": 0,
"createdSorting": 1396475366,
"subLists": "",
"subs": "",
"endCampaign": false,
"pageUrl": "http://l.gocella.com/T1d0NM5",
"sentAllTime": 0,
"sentThirtyDays": 0,
"sentNinetyDays": 0,
"votesAllTime": 0,
"votesThirtyDays": 0,
"votesNinetyDays": 0,
"entriesAllTime": 0,
"entriesThirtyDays": 0,
"entriesNinetyDays": 0,
"followsSentAllTime": 0,
"followsSentThirtyDays": 0,
"followsSentNinetyDays": 0
}
]
}
此对象在模型中具有belongsTo关系
答案 0 :(得分:1)
听起来,就像你将这些属性从JSON中删除一样,当强制转换为字符串时,它们的值为'undefined'
,而Ember-Data认为该字符串是有效的ID。 Ember-Data期望JSON中的这些属性,并且它期望它们的有效值,无论您的系统是否认为它们是可选的。您应该在JSON中包含这三个属性,如果关系不存在,则将它们设置为null
。