简体   繁体   English

Ember JS - 从Route Action更新/刷新模型数据

[英]Ember JS - Updating / Refreshing Model data From Route Action

This seems to be very simple problem but I can't find any solution for this. 这似乎是一个非常简单的问题,但我找不到任何解决方案。 I want to refresh the data for unprocessedDailyDataFile from action. 我想刷新数据unprocessedDailyDataFile从行动。 I can get the model by modelFor() method. 我可以通过modelFor()方法获得模型。 But when I try to use get() and set() method with the model they fails as undefined. 但是当我尝试将get()set()方法与模型一起使用时,它们会因未定义而失败。

Code for Route 路线代码

App.AdminRoute = Ember.Route.extend({
    model: function(){
        return {
            companies: this.store.find('company'),
            unprocessedDailyDataFiles: this.store.find('unprocessedDailyDataFile')
        };
    },
    actions: {
        reloadUnprocessedDailyDataFile: function(){
            var model = this.modelFor('admin');
            // both properties from the model is accessible here
            // model.get() fails
            // model.set() fails
        }
    }
});

For the model to reload, you can use 要重新加载模型,您可以使用

actions: {
           reloadUnprocessedDailyDataFile: function(){

               let  model =  this.get('controller.model'); // for Get and Set
               model.get('name'); 
               model.set({ name: 'john'});
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM