观察者不会在行为中工作?

时间:2017-04-26 22:08:47

标签: polymer polymer-1.0

我发现只有当我将observer分解为行为时,才会检测到任何变化。观察者是否无法用于行为?

    <iron-ajax
      auto="[[activated]]"
      url="[[HOST]][[LISTINGS]]/[[listingNumber]]"
      handle-as="json"
      verbose="true"
      with-credentials="true"
      on-error="_error"
      loading="{{loading}}"
      last-error="{{apiError}}"
      last-response="{{listing}}"></iron-ajax>

  </template>

  <script>
    Polymer({
      is: 'single-listing',
      behaviors: [ApiConstants, IronAjaxHelpers],
 <script>
  IronAjaxHelpers = {
    listingNumber: {
      type: Number,
      value: 0,
      notify: true
    },
    activated: {
      type: Boolean,
      value: false,
      observer: 'setListingNumber'
    },
    setListingNumber: function(newValue, oldValue) {
      console.log(newValue);  
      //this.listingNumber = id;
      if (newValue === true) {
        this.listingNumber = app.listingNumber;
      }
    }
  };
</script>

1 个答案:

答案 0 :(得分:1)

您的行为属性应在 require "stripe" def stripe_user_account return @stripe_user_account if defined? @stripe_user_account if Rails.env.production? Stripe.api_key = ENV['STRIPE_SECRET_KEY_PRO'] else Stripe.api_key = ENV['STRIPE_SECRET_KEY'] end Stripe::Account.list(limit: 99).each do |account| if account.email == self.email @stripe_user_account = account.id break end end @stripe_user_account end 字段中定义,但它当前位于行为对象的顶层。

您应该在行为中声明属性,如下所示:

properties

codepen