2015-02-09 68 views
1

我有以下代碼:燼,簡單-auth的更新數據

changeUsername: function(){ 
    var _this = this; 
    this.store.findById('user', this.session.get('user.id')).then(function(user){ 
     user.set('username', _this.get('newUsername')); 
     user.save(); 

     _this.session.set('user.username', _this.get('newUsername')); 
     _this.session.persist(); 
    }); 
} 

正如你所看到的 - 我堅持到餘燼簡單的權威性會議,我想在這個方法更新用戶對象。

呼叫持續在會話上並沒有辦法。

我也曾嘗試:

_this.session.store.set('user.username', _this.get('newUsername')); 
_this.session.store.save(); 

這也不能工作。

如何更新會話上的用戶對象?

回答

3

假設你已經擴展或重新開的與用戶id一個計算性能用戶的方法簡單的身份驗證會話的答案將是

var _this = this; 
    if(!Ember.isEmpty(this.get('session.content.userId'))) { 
    this.get('session.user').then(function(user){ 
     user.set('username', _this.get('newUsername')); 
     user.save(); 
    }); 
    } 

和您的模板將使用{{ session.user.username }}