Ember .observe() returns callback twice when used with query-params

让人想犯罪 __ 提交于 2020-01-11 13:05:41

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/23823343/ember-observe-returns-callback-twice-when-used-with-query-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!