Force to refresh ember view

让人想犯罪 __ 提交于 2019-12-24 13:32:55

问题


i have an ember view with a bunch of jquery code to manipulate the dom, the thing is when i use:

this.transitionTo("forecast.workpage", id);

it only loads the view once but when i try click it again the view doesn't execute again, i try several ways for instance adding this.rerender() in the end of my didInsertElement like that:

didInsertElement : function(){
//all my js code
this.rerender()
}

but it trows an error

Uncaught TypeError: Cannot read property '0' of undefined 

, try adding this._super() in the begin, same result, is there a way to force the view to refresh from the view itself or the route? or controller ?

edit: try this approach with no results...

didInsertElement : function(){      
        this._super();
        Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
    },

    afterRenderEvent: function(){

        //$(document).foundation();

        $(".sortables li:even").find('div.row').addClass("gray");


    }

Same thing, executes onces but where i click on the action doesn't execute the code.


回答1:


To re-render the whole route (page), you can use the route's refresh method. Or, as a possible solution to this.rerender() failing, you could call that after it renders the first time.

didInsertElement: function() {
    Ember.run.scheduleOnce('afterRender', this, function() {
        this.rerender();
    });
}

Personally, I wouldn't recommend either one. Your view should update automatically when the data it depends on changes. It if it's not updating, you probably have your observers set up wrong. (I don't really know your use case though, so use your best judgement.)



来源:https://stackoverflow.com/questions/25927159/force-to-refresh-ember-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!