私はPromiseの偽物を作っているかもしれませんが、ユーザーを認証した後、App.Session
私が作成したシングルトンにユーザーのプロファイルをロードしたいと思います:
App.Session.set(
'userProfile',
self.get('store').find('user',App.Session.get('userId'))
);
これにより、API 呼び出しが行われ、有効な結果セットが返されますが、デバッガーで何らかの理由で空の結果が得られます。具体的には、 は表示されますUser.id
が、残りの列は空白です。
デバッガーからの JSON 応答は次のとおりです。
{
"user": {
"id": "1",
"username": "jsmith",
"name": {
"first_name": "Joe",
"last_name": "Smith"
},
"emails": [
{
"id": "52153c0330063",
"name": "work-1",
"type": "other",
"address": "new@notreally.com",
"comments": "",
"status": "active",
"is_primary": false
},
{
"id": "52153d1b90ad0",
"name": "work-2",
"type": "other",
"address": "old@yesreally.com",
"comments": "",
"status": "active",
"is_primary": true
},
]
}
私はPromisesに少し慣れていないので、コードを次のように変更したと思いました:
self.get('store').find('user',App.Session.get('userId')).then( function(profile){
App.Session.set('userProfile', profile);
});
この新しいコードを書いたとき、私は新しい Promise の洞察力にかなり満足していました。悲しいことに、私の誇りに思った瞬間は失敗で迎えられました. 2 番目のコード スニペットは、最初のコード スニペットとまったく同じように動作します。は?
誰でも助けることができますか?
- - - - - ** アップデート ** - - - - -
のモデル定義User
と、参照したデバッガー ウィンドウの画像を含めました。
ユーザーモデル
App.RawTransform = DS.Transform.extend({
deserialize: function(serialized) {
return serialized;
},
serialize: function(deserialized) {
return deserialized;
}
});
App.NameTransform = DS.Transform.extend({
deserialize: function(serialized) {
return App.Name.create(serialized);
},
serialize: function(deserialized) {
return JSON.stringify(deserialized);
}
});
App.User = DS.Model.extend({
username: DS.attr("string"),
name: DS.attr("name"),
roles: DS.attr("raw"),
goals: DS.attr("raw"),
places: DS.attr("raw"),
emails: DS.attr("raw"),
networks: DS.attr("raw"),
relationships: DS.attr("raw"),
services: DS.attr("raw"),
uom: DS.attr("raw"),
});
デバッグ ウィンドウ
ログイン前のモデル ビューアーは次のように表示されます。
その後、ログインすると次のようになります。
レコードの詳細を見ると、次のように表示されます。