코드로 mvvm 원리를 해석하다

1243 단어



    
    Document


    

var model = { title:' ', setTitle:function(title){ this.title = title; flush(); } }; function flush(){ // var itcastScope = document.querySelector('[itcast-controller]'); // var itcastValueArr = document.querySelectorAll('[itcast-value]'); var itcastContArr = document.querySelectorAll('[itcast-cont]'); for(var i=0;i<itcastValueArr.length;i++){ itcastValueArr[i].value = model[itcastValueArr[i].getAttribute("itcast-value")]; itcastValueArr[i].oninput = function(){ model.setTitle(this.value); }; } for(var i=0;i<itcastValueArr.length;i++){ itcastContArr[i].innerHTML = model[itcastContArr[i].getAttribute("itcast-cont")]; } } flush();

좋은 웹페이지 즐겨찾기