[英]Response from the server when saving a record to set the id ember-data
在使用selection.save()
保存记录后,其中selection是我的模型,未在模型上设置id。 我当前的服务器响应与show的json相同。 即: selection: {id: <id>}
和其他字段。 购买ID未在ember数据本地存储中设置。 我使用默认的RESTAdapter和Rails作为后端。 (我使用jbuilder for JSON)
model是MatchPlayerSelection
,一旦我保存记录,这就是我发回的响应:
{"match_player_selection":{"id":41298,"user":3,"scheduledMatch":133,"matchPlayerScores":[3697,3696,3694,3698,3704,3719,3712,3709,3717,3707,3714],"captain":3694,"viceCaptain":3709}
你是如何测试id
设置的? save
函数是异步并返回一个promise,因此您需要在检查id
之前解析promise。
这不起作用:
selection.save();
console.log( selection.get('id') );
这将工作:
selection.save().then(function(savedSelection){
console.log( savedSelection.get('id') );
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.