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

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

问题描述

http://jsbin.com/vowup/2



如果我单击更改为随机,程序将登录到控制台两次。



由于某些奇怪的原因,将修订版本变量设置为字符串,但日志

解决方案

将代码更改为此,答案将变得清楚:

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

您将看到如下输出:

  0.7038348997011781 
0.7038348997011781


$ b $你的电话号码被胁迫到字符串。这是由这一行引起的:

  queryParams:[revision] 
/ pre>

查询系统正在监听更改并将每个新值转换为字符串,因此可能会显示为URL的一部分。这就是为什么你得到两个改变的事件。


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

You will see output like:

0.7038348997011781
"0.7038348997011781"

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

queryParams: ["revision"]

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天全站免登陆