diff --git a/avalon.js b/avalon.js index 7f4beb80c..b734bd885 100644 --- a/avalon.js +++ b/avalon.js @@ -1798,22 +1798,28 @@ } } } else if (special === "up" || special === "down") { - var element = events.expr && findNode(events.expr) - if (!element) + var elements = events.expr && findNodes(events.expr) + if (elements.length === 0) return for (var i in avalon.vmodels) { var v = avalon.vmodels[i] if (v !== this) { if (v.$events.expr) { - var node = findNode(v.$events.expr) - if (!node) { + var eventNodes = findNodes(v.$events.expr) + if (eventNodes.length === 0) { continue } - var ok = special === "down" ? element.contains(node) : //向下捕获 - node.contains(element) //向上冒泡 - if (ok) { - node._avalon = v //符合条件的加一个标识 - } + //循环两个vmodel中的节点,查找匹配(向上匹配或者向下匹配)的节点并设置标识 + avalon.each(eventNodes, function(i, node) { + avalon.each(elements, function(j, element) { + var ok = special === "down" ? element.contains(node) : //向下捕获 + node.contains(element) //向上冒泡 + + if (ok) { + node._avalon = v //符合条件的加一个标识 + } + }); + }) } } } @@ -1849,16 +1855,18 @@ } } var ravalon = /(\w+)\[(avalonctrl)="(\S+)"\]/ - var findNode = DOC.querySelector ? function(str) { - return DOC.querySelector(str) + var findNodes = DOC.querySelectorAll ? function(str) { + return DOC.querySelectorAll(str) } : function(str) { var match = str.match(ravalon) var all = DOC.getElementsByTagName(match[1]) + var nodes = [] for (var i = 0, el; el = all[i++]; ) { if (el.getAttribute(match[2]) === match[3]) { - return el + nodes.push(el) } } + return nodes } /********************************************************************* * 依赖调度系统 * diff --git a/examples/$fire3.html b/examples/$fire3.html new file mode 100644 index 000000000..97cbc062e --- /dev/null +++ b/examples/$fire3.html @@ -0,0 +1,36 @@ + +
+ +