d3错误:"节点不能插入层次结构中的指定点"

时间:2014-11-16 13:38:19

标签: javascript d3.js

我尝试将标题添加到标题列表中,然而“不幸的是我被困了 错误:

HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy

这是极其简单的代码:

<!DOCTYPE html>
    <html>
        <head>           
            <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
            <script>
            function start2()
            {
                data               =  [ { titre : " subtitle 1"  }   , 
                                        { titre : " subtitle 2"  }   , 
                                        { titre : " subtitle 3"  }   , 
                                        { titre : " subtitle 4"  }   , 
                                        { titre : " subtitle 5"  }   ]   ;

                Updated_dom= d3 .selectAll  (   "h1"    )
                                .data       (   data    );

                Updated_dom.append     (   "h2"    )
                           .text       (   function(d){ return d.titre;}   );

                Updated_dom .enter()
                            .append("h1")
                            .text(  function(d) {  return "new title : " + d.titre ;  }   );

            }

            </script>
        </head>
        <body onload=start2()>
                <h1>Title 1</h1>
                <h1>Title 2</h1>
                <h1>Title 3</h1>

        </body>
    </html>

在给出错误之前给出了部分结果:

<body onload="start2()">
    <h1>
        Title 1
        <h2>
             subtitle 1
        </h2>
    </h1>
    <h1>
        Title 2
         <h2>
             subtitle 2
        </h2>
    </h1>
    <h1>
        Title 3
        <h2>
            subtitle 3
         </h2>
    </h1>
</body>

知道发生了什么事吗?

此外,我想知道如何让“h2”在“h1”之后(而不是“今天”之下),即获得:

    <h1>
         title 1
    </h1>
    <h2>
        subtitle 1
    </h2>

第二点的帮助也欢迎;)

谢谢, 罗曼。

0 个答案:

没有答案