观察者不会工作在一个行为上吗?

Observer will not work in a behavior?

我发现只有当我把一个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>

您的行为属性应该在 properties 字段中定义,但它目前位于行为对象的顶层。

您应该像这样在行为中声明属性:

IronAjaxHelpers = {
  properties: {
    /** PROPERTIES GO HERE **/

    listingNumber: {
      type: Number,
      value: 0,
      notify: true
    },
    activated: {
      type: Boolean,
      value: false,
      observer: "setListingNumber"
    }
  },

  setListingNumber: function(newValue, oldValue) {
    console.log(newValue);
  }
};

codepen