【问题标题】:Polymer 1.0: How to nest functions?Polymer 1.0:如何嵌套函数?
【发布时间】:2015-09-23 07:14:53
【问题描述】:

我想调用一个观察者函数'_propChanged',它又调用另外两个_foo()_bar()。我该怎么做?

代码

{
  is: 'x-el',
  properties: {
    prop: {
      type: String,
      notify: true,
      observer: '_propChanged'
    }
  },
  _propChanged: function() {
    _foo(); // This doesn't work
    _bar(); // This doesn't work
  },
  _foo: function() {
    // Do stuff
  },
  _bar: function() {
    // Do stuff
  }
}

【问题讨论】:

  • 在您的 _observePropChanges 函数中尝试使用 this._foo()this._bar()
  • @miqid 应该这样做。为什么不将其添加为答案?

标签: polymer polymer-1.0


【解决方案1】:

只需在函数调用前加上 this 即可正确解析名称。

_observePropChanges: function () {
  this._foo();
  this._bar();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多