当与查询参数一起使用时,Ember .observe() 返回回调两次 [英] Ember .observe() returns callback twice when used with query-params

查看:31
本文介绍了当与查询参数一起使用时,Ember .observe() 返回回调两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://jsbin.com/vowup/2

如果我点击更改为随机,程序会在控制台登录两次.

If I click change to random, program logs in console twice.

出于某种奇怪的原因,将修订版变量设置为字符串时它可以正常工作,但为数字或任何其他类型的变量记录两次

For some strange reason it works ok when setting revision variable to string, but logs twice for number or any other kind of variable

推荐答案

把你的代码改成这样,答案就清楚了:

Change your code to this and the answer will become clear:

  toggleHistory: (function() {
    console.log(this.get("revision"));
  }).observes("revision")

您将看到如下输出:

0.7038348997011781
"0.7038348997011781"

您的数字被强制转换为字符串.这是由这一行引起的:

Your numbers are being coerced to strings. That is caused by this line:

queryParams: ["revision"]

查询系统正在侦听更改并将每个新值转换为字符串,因此它可以作为 URL 的一部分出现.这就是为什么您会收到两个更改的事件.

Query system is listening to changes and converting every new value into string, so it could appear as part of the URL. That's why you get two changed events.

这篇关于当与查询参数一起使用时,Ember .observe() 返回回调两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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