2014-08-29 3 views
1

DIV의 내용이 다른 방식으로 바뀌면 특정 노드/하위 변경 내용을 듣고 싶을 때 스크립트를 실행하고 싶습니다. JavaScript에서 "DOMSubtreeModified"라는 것을 발견했습니다. this fiddleDart lang의 DOM 변경 리스너

$("#someDiv").bind("DOMSubtreeModified", function() { 
    alert("tree changed"); 
}); 

DART와 비슷한 것이 있습니까?

+0

Dart가 자바 스크립트로 컴파일되고 대부분의 브라우저는 하위 트리 수정 이벤트를 제공하지 않으므로 Dart에서 수행 할 수 없습니다. – Barmar

+0

MutationObserver for this this http://stackoverflow.com/questions/18927901 http://caniuse.com/#feat=mutationobserver https://developer.mozilla.org/en/docs/Web/API/ MutationObserver –

+0

@Barmar Dart는 최신 브라우저 용 JavaScript로 컴파일됩니다. 최신 브라우저로 할 수 있다면 다트가 할 수 있습니다. –

답변

4

감사 @Gunter Zochbauer은, 당신이 준 권장 사이트와 함께 , 나는 DART에 MountainObserver에 대해 this을 발견하고, 아래의 코드는 index.html을 나를 :) 완벽하게

main(){ 
    ... 
    Element myDiv = querySelector('#my-element'); 
    var observer = new MutationObserver((mutations, _) { 
      mutations.forEach((mutation) { 
       print('number of direct nodes here are: ${myDiv.nodes.length}');; 
     }); 
    }); 
    observer.observe(myDiv, childList: true); 
    .... 
    } 

근무 나는

<div id='my-element'></div>