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