2015-10-06 99 views
1

我有一個顯示挑戰列表的路線,當我創建新的挑戰時,記錄被保留,但是當我轉換回路線時,挑戰列表的模型不會更新。有什麼我失蹤?Ember模型未更新

//new.js 
var challenge = this.store.createRecord('challenge', { 
      name_en: this.get('model.name_en'), 
      name_fr: this.get('model.name_fr'), 
      description_en: this.get('model.description_en'), 
      description_fr: this.get('model.description_fr'), 
      end_date: this.get('model.end_date'), 
      start_date: this.get('model.start_date'), 
      points_cap: this.get('model.points_cap'), 
      points_goal: this.get('model.points_goal'), 
      challenge_type: 1, 
      short_description_en: this.get('model.short_description_en'), 
      short_description_fr: this.get('model.short_description_fr'), 
      excluded_activities: excluded 
     }); 

     // Persist record. 
     challenge.save().then((challenge) => { 
      this.transitionToRoute('challenges'); 
     }).catch((error) => { 
      this.handleError(error, 'error.system_error'); 
     }); 

//router.js 
Router.map(function() { 
    this.route('challenges', function() { 
    this.route('new'); 
    this.route('challenge', { 
    path: ':challenge_id' 
}, function() { 
    this.route('delete'); 
    this.route('edit'); 
}); 

});

//challenges.js 
import Ember from 'ember'; 
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'; 
import UserProfile from '../models/user-profile'; 

export default Ember.Route.extend(AuthenticatedRouteMixin,{ 

userProfile: UserProfile.create(), 

model: function() { 
    return this.store.query('challenge', {league_id: this.get('userProfile.league_id')}); 
} 

});

//new challenge payload 
{ 
"activity_exclusion_list":[ 

], 
"challenge_type":1, 
"challengeUrl":null, 
"end_date":"31-10-2015", 
"number_participants":null, 
"number_teams":null, 
"points_cap":null, 
"points_goal":null, 
"start_date":"01-10-2015", 
"leagueId":"1", 
"teams":[ 

], 
"name_lang":{ 
    "en":"New Challenge ", 
    "fr":null 
}, 
"description_lang":{ 
    "en":"New Challenge", 
    "fr":null 
}, 
"short_description_lang":{ 
    "en":"New Challenge", 
    "fr":null 
} 

}

//response from new challenge 
{ 
"challenge_type":"Individual", 
"description":" ", 
"description_fr":null, 
"description_lang":{ 
    "en":"New Challenge", 
    "fr":null 
}, 
"challengeUrl":" ", 
"start_date":"01-10-2015", 
"end_date":"31-10-2015", 
"name":" ", 
"name_fr":null, 
"name_lang":{ 
    "en":"New Challenge ", 
    "fr":null 
}, 
"points_cap":0, 
"points_goal":0, 
"short_description":" ", 
"short_description_fr":null, 
"short_description_lang":{ 
    "en":"New Challenge", 
    "fr":null 
}, 
"number_participants":0, 
"number_teams":0, 
"teams":[ 

], 
"challenge_id":265, 
"activity_exclusion_list":[ 

], 
"leagueId":1 

}

+0

乍一看似乎沒問題。你可以提供你的挑戰路線,看看你是如何檢索模型? –

+0

當然你在這裏 – jpoiri

+0

我假設你正在使用'this.store.query'因爲'league_id'不是你的主體id,對吧?那麼在你的'createRecord'中,你在哪裏設置'league_id'? –

回答

0

在你的挑戰路線你嘗試過使用this.store.filter呢?問題可能是查詢函數只返回一個RecordArray,而過濾器返回一個Live RecordArray,它會在承諾(在這種情況下是成功保存)解析後更新模板和其他所有內容。

model: function() { 
    return this.store.filter('challenge', {league_id: this.get('userProfile.league_id')}, function() { 
     // We're not actually filtering, so just return true for everything 
     return true; 
    }); 
} 

我有同樣的問題,這原來是解決方案,希望它有幫助!

Ember Docs reference

+0

謝謝,究竟是什麼是我的問題 – jpoiri