diff --git a/src/core/4.widget.js b/src/core/4.widget.js index bba3c5baa6..fff25e6297 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -170,7 +170,9 @@ this.element = BI.Widget._renderEngine.createElement(this); } this.element._isWidget = true; - (this.element[0]._Widgets = this.element[0]._Widgets || []).push(this); + var widgets = this.element.data("_Widgets") || []; + widgets.push(this); + this.element.data("_Widgets", widgets); this._initCurrent(); }, @@ -223,11 +225,19 @@ } if (BI.isArray(els)) { if (this.options.vdom) { - this.vnode = this._renderVNode(); var div = document.createElement("div"); - this.element.append(div); + var element = this.element; + element.append(div); + this.vnode = this._renderVNode(); BI.patchVNode(div, this.vnode); - // this.element = $(div); + // 去除这个临时的div + BI.DOM.hang([div]); + element.attr("style", self.vnode.elm.getAttribute("style")); + element.addClass(self.vnode.elm.getAttribute("class")); + element.empty(); + BI.each(BI.jQuery(self.vnode.elm).children(), function (i, node) { + element.append(node); + }) } else { BI.each(els, function (i, el) { if (el) { @@ -264,7 +274,7 @@ } }); } - return BI.Element2Snabbdom(container); + return BI.Element2Vnode(container); }, _setParent: function (parent) { diff --git a/src/core/element2Snabbdom.js b/src/core/element2Snabbdom.js index 2d063df6e2..b568c2a7b3 100644 --- a/src/core/element2Snabbdom.js +++ b/src/core/element2Snabbdom.js @@ -1,8 +1,8 @@ !function () { var patch = BI.Snabbdom.init([BI.Snabbdom.attributesModule, BI.Snabbdom.classModule, BI.Snabbdom.datasetModule, BI.Snabbdom.propsModule, BI.Snabbdom.styleModule, BI.Snabbdom.eventListenersModule]); - BI.Element2Snabbdom = function (parentNode) { + BI.Element2Vnode = function (parentNode) { if (parentNode.nodeType === 3) { - return parentNode.textContent; + return BI.Snabbdom.vnode(undefined, undefined, undefined, parentNode.textContent, parentNode); } var data = BI.jQuery._data(parentNode); var on = {}; @@ -14,26 +14,31 @@ }); }; }); - var style = parentNode.getAttribute("style"); + var attrs = {}; + var elmAttrs = parentNode.attributes; + var elmChildren = parentNode.childNodes; var key = parentNode.getAttribute("key"); - // var claz = parentNode.getAttribute("class"); - var vnode = BI.Snabbdom.h(parentNode.nodeName, { + for (i = 0, n = elmAttrs.length; i < n; i++) { + var name = elmAttrs[i].nodeName; + if (name !== "id" && name !== "class") { + attrs[name] = elmAttrs[i].nodeValue; + } + } + var vnode = BI.Snabbdom.vnode(parentNode.nodeName, { class: BI.makeObject(parentNode.classList), - props: { - style: style - }, + attrs: attrs, key: key, on: on, hook: { create: function () { - BI.each(parentNode._Widgets, function (i, w) { + BI.each(BI.Widget._renderEngine.createElement(parentNode).data("_Widgets"), function (i, w) { w.element = BI.Widget._renderEngine.createElement(vnode.elm); }); } } - }, BI.map(parentNode.childNodes, function (i, childNode) { - return BI.Element2Snabbdom(childNode); - })); + }, BI.map(elmChildren, function (i, childNode) { + return BI.Element2Vnode(childNode); + }), undefined, parentNode); return vnode; };