Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML插值绑定有BUG #3

Closed
Gaubee opened this issue Jun 13, 2013 · 1 comment
Closed

HTML插值绑定有BUG #3

Gaubee opened this issue Jun 13, 2013 · 1 comment

Comments

@Gaubee
Copy link

Gaubee commented Jun 13, 2013

photo.js

vm.monument = [{title:"",descriptions:""}];//结构为数组型,内Object数量会变动(但是这个并不是BUG的来源),descriptions是HTML格式的数据

photo.html

<div ms-each-md="monument" class="row">
  <div class="span4">
    <h2>{{md.title}}</h2>
    <p ms-visible="md.ishowDetail" ms-html="md.descriptions"></p> <!-- 使用ms-html -->
    <p ms-visible="md.ishowDetail">{{md.descriptions|html}}</p> <!-- 直接插入 -->
  </div>
</div>

初次显示很OK,但是当vm.monument进行变动时:

vm.monument = [{title:"",descriptions:""},{title:"",descriptions:""}];

如果使用{{md.descriptions|html}} 会抛出异常:

Uncaught Error: NotFoundError: DOM Exception 8 avalon.js:1575
(anonymous function) avalon.js:1575
updateView avalon.js:1285
notifySubscribers avalon.js:1041
accessor avalon.js:881
updateViewModel avalon.js:803
Collection.collection.set avalon.js:1894
updateViewModel avalon.js:798
accessor avalon.js:871
routerHash photo.js:376
avalon.Router.navigate avalon.router.js:375
self.checkUrl avalon.router.js:124
@RubyLouvre
Copy link
Owner

 实在太感谢你的测试了,这个BUG已经修复

"html": function(data, vmodels) {
            watchView(data.value, vmodels, data, function(val, elem) {
                val = val == null ? "" : val + ""
                if (data.replaceNodes) {
                    domParser.innerHTML = val
                    var replaceNodes = []
                    while (domParser.firstChild) {
                        replaceNodes.push(domParser.firstChild)
                        documentFragment.appendChild(domParser.firstChild)
                    }
                    elem.insertBefore(documentFragment, data.replaceNodes[0]);
                    for (var i = 0, node; node = data.replaceNodes[i++]; ) {
                        elem.removeChild(node)
                    }
                    data.replaceNodes = replaceNodes
                } else {
                    elem.innerHTML = val
                }
            })
        },

RubyLouvre pushed a commit that referenced this issue Sep 24, 2013
RubyLouvre pushed a commit that referenced this issue Sep 28, 2014
RubyLouvre pushed a commit that referenced this issue Nov 21, 2014
merge from RubyLouvre/avalon
RubyLouvre pushed a commit that referenced this issue May 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants