2017-03-02 40 views

回答

0

您可以使用MutationObserver做你所需要的。

您設立觀察員對你的DivElement和觀察childList突變。在MutationRecord中,您可以獲得addedNodes列表。

沒有爲MutationObserver沒有原生GWT的支持,所以你需要使用JSNI:

private native void addListener(Element elem) /*-{ 
    // create an observer instance 
    var observer = new MutationObserver(function(mutations) { 
     mutations.forEach(function(mutation) { 
      if(mutation.type == 'childList') { 
       // mutation.addedNodes contains nodeList of added nodes 
       $wnd.alert('Nodes added'); 
      } 
     }); 
    }); 

    // configuration of the observer: 
    var config = { 
     childList : true 
    }; 

    // pass in the target node, as well as the observer options 
    observer.observe(elem, config); 
}-*/; 

只需撥打addListener(div);您的DivElement。

相關問題