强制刷新余烬视图 [英] Force to refresh ember view

查看:157
本文介绍了强制刷新余烬视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆用jquery代码来操纵dom的ember视图,事情是当我使用时:

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()
}



$ p
$ b

but it trows an error

Uncaught TypeError: Cannot read property '0' of undefined 

,请尝试在begin中添加this._super(),结果相同,是否有办法强制视图从查看自己或路线?或控制器?

, 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.

推荐答案

要重新渲染整个路线(页面),您可以使用路线的刷新方法。或者,作为 this.rerender()失败的可能解决方案,您可以在第一次呈现它之后调用

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.)

这篇关于强制刷新余烬视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆