ember.js clearInterval不工作 [英] ember.js clearInterval not working

查看:152
本文介绍了ember.js clearInterval不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

App.Controller = Ember.ObjectController.extend({
    timerStart: function () {


        this.timer = setInterval(this.ctimer, 1000);


    },


    timerEnd: function () {

        this.clearInterval(this.ctimer);

    },

    ctimer: function () {

        var d = new Date();
        document.getElementById("timeBar").innerHTML = d.toLocaleTimeString();

       }
});

,因为clearInterval函数不能像调用timerEnd函数那样工作。

in ember.js, the clearInterval function not working as I call the timerEnd function.

什么是正确的方法来解决这个代码的问题。谢谢。

what is right way to fix the problem on this code. Thank you.

推荐答案

尝试添加计时器变量并清除该变量而不是ctimer。 (未测试)

Try adding the timer variable and clearing that one instead of the ctimer. (Not tested)

App.Controller = Ember.ObjectController.extend({  
  timer: null,
  timerStart: function () {
      this.timer = setInterval(this.ctimer, 1000);
  },
  timerEnd: function () {
      this.clearInterval(this.timer);
  },
  ctimer: function () {
      var d = new Date();
      document.getElementById("timeBar").innerHTML = d.toLocaleTimeString();
  },
});

这篇关于ember.js clearInterval不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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