2016-03-25 16 views
0

Facebook gibi hissettiren bildirimler oluşturmak istiyorum. Polimer ve elemanlar kullanıyorum: iron-dropdown, iron-list, iron-scroll-threshold. Açılan açılır menüden sonra bir iron-scroll-threshold öğesi oluşturmak istiyorum. Ben ilk oluşturduğunuzda zaman bir olay ateş edeceği ve bu gibi kullanabilirsiniz, böylece yüklemeninbaşlamasını:Polimer tarafından dinamik olarak oluşturulmuş öğe wokring (demir-kaydırma eşiği)

<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> 

Ve komut şöyledir: elementler oluşturulduğunda

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(); 
} 

Ama öyle değil iş. Etkinlik asla kovulmayacak. Herhangi bir fikir?

cevap

1

Özniteliklerle bağlamaya çalıştığınız etkinlik için addEventListener kullanmayı denediniz mi? Benim tahminim bu doğru bir şekilde ele alınmıyor (çünkü Polimer henüz programsal olarak bağlayıcı şeyleri desteklemiyor).

+0

herhangi bir fikri nasıl kullanır? Kesinlikle dinleyiciler hakkında sorun var ama bu sorunu nasıl çözdüğüm hakkında hiçbir fikrim yok. Öğe normal olarak oluşturulduğunda her şey çalışır, ancak yarattığım zaman dinamik olarak eleman yaratılır ama dinleyicilerin çalıştıkları veya kayıtlı olmadıklarını düşünüyorum. –

+0

@ktiedt doğrudur. Bu noktada genişletmek için: Bir öğenin şablonunda 'on-lower-threshold =" foo "' kullandığınızda, Polymer, elemanın prototipinde "foo" adlı işleyiciyi arar. Bu programsal olarak ayarlarsanız, işleyiciyi nerede bulacağını bilmez. Olayı zorunlu olarak ele almak için: 'var handler = this._loadData.bind (this); scrollThreshold.addEventListener ('alt eşik', işleyici); ' – DocDude

İlgili konular