2016-03-25 7 views
0

Facebookのような感じの通知を作成したいと思います。私はポリマーと要素を使用します:iron-dropdowniron-listiron-scroll-threshold。ドロップダウンが開いた後にiron-scroll-threshold要素を作成したいと思います。私はそれを最初に作成するときには、イベントが発生し、私はこのようにそれを使用するので、ロードを開始します:動的に作成されたポリマーではないwokring(iron-scroll-threshold)

<template> 
     <iron-ajax 
       id="ajax" 
       url="some url" 
       handle-as="json" 
       on-response="_handleResponse"> 
     </iron-ajax> 

     <paper-button class="status-bar-button" on-tap="open"> 
      <iron-icon icon="social:notifications-none"></iron-icon> 
     </paper-button> 

     <iron-dropdown id="dropdown" 
         vertical-align="[[verticalAlign]]" 
         horizontal-align="[[horizontalAlign]]" 
         disabled="[[disabled]]" 
         open-animation-config="[[openAnimationConfig]]" 
         close-animation-config="[[closeAnimationConfig]]" 
         horizontal-offset="[[horizontalOffset]]" 
         vertical-offset="[[verticalOffset]]"> 

      <div id="sidebar-apps-container" class="dropdown-content shadow-elevation-8dp"> 
       <div class="beeper" style="right:128px"></div> 
       <div class="apps-body" id="scrollThresholdtarget"> 
        <iron-list id="zoznam" items="[]" as="notifs" scroll-target="scrollThresholdtarget"> 
         <template> 
          <a href="[[notifs.link]]" style="height: 150px">[[notifs.content]]</a><br/> 
         </template> 
        </iron-list> 
       </div> 
      </div> 
     </iron-dropdown> 

     <div id="forThreshold"></div> 
    </template> 

、スクリプトはこのように書き:

open: function() { 
    if (!this.scrollInitialised) { 
     this.initScrollThreshold(); 
     this.scrollInitialised = true; 
    } 

    this.$.dropdown.open(); 
}, 

/** 
* @method 
*/ 
initScrollThreshold: function() { 
    var scrollThreshold = document.createElement('iron-scroll-threshold'); 
    scrollThreshold.setAttribute('id', 'threshold'); 
    scrollThreshold.setAttribute('on-lower-threshold', '_loadData'); 
    scrollThreshold.setAttribute('lower-threshold', '200'); 
    scrollThreshold.setAttribute('scroll-target', 'scrollThresholdtarget'); 
    this.$.forThreshold.appendChild(scrollThreshold); 
    this._loadData(); 
}, 

/** 
* @method 
*/ 
_handleResponse: function (event) { 
    var data = event.detail.response; 

    console.log(data); 
    var elem = this.$.zoznam; 

    data.forEach(function(notifs) { 
     elem.push('items', notifs); 
    }); 

    document.querySelector('#threshold').clearTriggers(); 
    console.log('fired'); 
}, 

/** 
* @method 
*/ 
_loadData: function() { 
    console.log('fired request'); 
    this.$.ajax.generateRequest(); 
} 

しかし、要素が作成されたとき、それはありません作業。イベントは決して解雇されません。何か案は?

答えて

1

属性を使用してバインドしようとしているイベントにaddEventListenerを使用してみましたか?私の推測では、それは正しく処理されていないということです(Polymerはプログラム的にバインドすることをまだサポートしていないので)。

+0

どのように使っているのでしょうか?間違いなくリスナーに関する問題がありますが、どのようにこの問題を解決するのか分かりません。要素が正常に作成されたときはすべて正常に機能しますが、idを動的に作成すると要素が作成されますが、リスナーは正しく動作しているか登録されていないと思います。 –

+0

@ktiedtが正しいです。この時点で展開するには:要素のテンプレートで 'on-lower-threshold =" foo "'を使うと、Polymerは要素のプロトタイプで 'foo'という名前のハンドラを探します。これをプログラマチックに設定すると、ハンドラの場所を知ることができません。イベントを即座に処理するには、 'var handler = this._loadData.bind(this); scrollThreshold.addEventListener( 'lower-threshold'、ハンドラ); ' – DocDude

関連する問題