[英]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.