0
得到模型

我在航線只想刷新模式,同時充分利用控制器的作用,在這條線路上運行doRefresh行動不能從路線行動燼

這是我的代碼

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    profileFormService: Ember.inject.service(), 
    profileFormAtributeService: Ember.inject.service(), 
    model(){ 
    return Ember.RSVP.hash({ 
     profileForms: this.get('profileFormService').find(), 
     profileFormsAttributes: this.get('profileFormAtributeService').findByProfileFormId("1"), 
     inputTypes: {data: ['CHECKBOX', 'NUMBER_FIELD', 'PHONE_NUMBER', 'TEXT_FIELD', 'EMAIL', 'TEXT_AREA', 'RADIO_BUTTON', 'DESA', 'KABUPATEN_KOTA', 'PROVINSI', 'KECAMATAN', 'MAP_POINT', 'MAP_POLYGON']} 
    }); 
    }, 
    setupController(controller, model) { 
    this.controllerFor('backend.setting-profile-form-attribute').set('profileForms', model.profileForms); 
    this.controllerFor('backend.setting-profile-form-attribute').set('profileFormsAttributes', model.profileFormsAttributes); 
    this.controllerFor('backend.setting-profile-form-attribute').set('inputTypes', model.inputTypes); 
    }, 
    actions:{ 
    doRefresh(param){ 
     let context = this; 
     this.get('profileFormAtributeService').findByProfileFormId(param).then(function (response) { 
     context.set("profileFormsAttributes",response); 
     }), function (e) { 
     this.debug(e); 
     }; 
    } 
    } 
}); 

不幸的是,這是不'nt影響profileFormsAttributes模型。

我已經奔試圖調試與模型此

this.debug(this.get('controller.model.profileFormsAttributes')) 
this.debug(this.get('model.profileFormsAttributes')); 

但控制檯日誌說不確定

可以解決這一點,並解釋這是我的路線發生什麼..

感謝您的關注

回答

1

你的問題是,你不能實現從路由內返回的對象在行動處理程序直接像this.get('profileFormsAttributes');因此您的設置不起作用。

this.get('controller.model.profileFormsAttributes'); 
this.get('model.profileFormsAttributes'); 

即使在兩個語句之上也不起作用;因爲你不能像這樣檢索modelcontroller

你有兩個選擇;要麼你需要保存你會從模型直接model鉤內的this.set('model', model)返回什麼,或者你可以用this.controllerFor(this.get('routeName')).get('model')

實現它,我會建議爲你的情況下,第二種方法。請看下面的twiddle,我已經準備好爲你說明情況。

請看看index.js其中對象的屬性foomodel鉤返回設置與

Ember.set(this.controllerFor(this.get('routeName')).get('model'), 'foo', 'foo updated'); 

我希望這有助於。

+0

感謝他們現在的工作:) – cahyowhy