From 07a26442e62d16af0ae40fcf22d120d5b73dcfe2 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Tue, 18 Nov 2014 11:31:47 +0800 Subject: [PATCH] add checkScan --- avalon.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/avalon.js b/avalon.js index a71360294..7cc324c90 100644 --- a/avalon.js +++ b/avalon.js @@ -2017,6 +2017,17 @@ //http://www.w3.org/TR/html5/syntax.html#void-elements var stopScan = oneObject("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase()) + function checkScan(elem, callback, innerHTML) { + var id = setTimeout(function() { + var currHTML = elem.innerHTML + clearTimeout(id) + if (currHTML === innerHTML) { + callback() + } else { + checkScan(elem, callback, currHTML) + } + }) + } function scanTag(elem, vmodels, node) { //扫描顺序 ms-skip(0) --> ms-important(1) --> ms-controller(2) --> ms-if(10) --> ms-repeat(100) @@ -2650,11 +2661,10 @@ text = loaded.apply(target, [text].concat(vmodels)) } if (rendered) { - avalon.scanCallback(function() { + checkScan(target, function() { rendered.call(target) - }) + }, NaN) } - avalon.scan(target) while (true) { var node = data.startInclude.nextSibling if (node && node !== data.endInclude) { @@ -2881,13 +2891,12 @@ } var callback = data.renderedCallback || noop, args = arguments - avalon.scanCallback(function() { + checkScan(parent, function() { callback.apply(parent, args) if (parent.oldValue && parent.tagName === "SELECT" && method === "index") { //fix #503 avalon(parent).val(parent.oldValue.split(",")) } - }) - avalon.scan(parent) + }, NaN) } }, "html": function(val, elem, data) { @@ -3655,12 +3664,11 @@ } } data.bound("change", updateVModel) - avalon.scanCallback(function() { + checkScan(element,function() { //先等到select里的option元素被扫描后,才根据model设置selected属性 registerSubscriber(data) data.changed.call(element, evaluator(), data) - }) - avalon.scan(element) + }, NaN) } duplexBinding.TEXTAREA = duplexBinding.INPUT //============================= event binding =======================