本文介绍了轮播在初始重定向时中断,但在刷新时正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有关于"链接的导航栏.单击后,它应该会弹出一个子导航,并将您重定向到"about.philosophy"而不是"about.index".

I have a nav bar with an 'About' link. When clicked it should bring up a subnav and redirect you to 'about.philosophy' rather than 'about.index', which it does.

我在about.hbs模板上渲染了一个轮播部分:

I have a carousel partial I'm rendering on the about.hbs template:

<div class="row about-bg">
    {{partial 'about/about-carousel'}}
</div>
{{outlet}}

这是在AboutView中触发的:

That is being fired in the AboutView:

Ew.AboutView = Ember.View.extend({
  didInsertElement : function(){
    $(window).load(function() {
        $("#about-carousel").carouFredSel({
            responsive: true,
            width: "100%",
            height: 'variable',
            items: {
            height: 'variable'
            }
        });
    });
   }
});

但是,当第一次单击关于"链接时,将URL更改为"/about/philosophy"时,轮播被破坏了-所有图像都堆叠在一起并且没有运动-就像js找不到或什么.但是,当我在浏览器中点击刷新时,轮播会正常显示.必须是重定向破坏了它,因为当ember不触发重定向时,它在刷新时效果很好.

However, when the 'About' link is first clicked, changing the url to '/about/philosophy', the carousel is broken -- all the images just stacked on top of one another and no movement -- like the js isn't being found or something. But as soon as I hit refresh on my browser the carousel renders fine. It must be the redirect that is breaking it, because it works fine on refresh when ember isn't firing the redirect.

重定向功能以及subnav呈现代码位于AboutIndexRoute中:

The redirect function, along with subnav rendering code is in AboutIndexRoute:

Ew.AboutIndexRoute = Ember.Route.extend({
  activate: function(){
    this.controllerFor('application').set('renderAboutSubNav', true);
  },
  deactivate: function(){
    this.controllerFor('application').set('renderAboutSubNav', false);
  },
  redirect: function(){
    this.transitionTo('about.philosophy');
  }
});

子导航也无法显示.

非常感谢!

推荐答案

从您的 didInsertElement 中删除 $(window).load(function(){}); 包装器>方法.

Remove the $(window).load(function() {}); wrapper from your didInsertElement method.

这篇关于轮播在初始重定向时中断,但在刷新时正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 14:29