简体   繁体   English

如何通过createElement()在聚合物中添加扩展元素

[英]How to add extended elements in polymer by createElement()

 var elm = document.createElement("tr");                
 this.$.myLovelyContainer.appendChild(elm);

I need to add a <tr is="custom-tag"...> node in myLovelyContainer. 我需要在myLovelyContainer中添加一个<tr is="custom-tag"...>节点。

Thx for help guys :) 谢谢帮忙:)

--- more info I just saw ---我刚刚看到的更多信息

The problem is when I add this via document.createelement , it creates but does not create the content of it. 问题是当我通过document.createelement添加它时,它创建但不创建它的内容。 This is an extended tr element that has td tags in it. 这是一个扩展的tr元素,其中带有td标签。

It just adds the tag in page but it is always invisible. 它只是在页面中添加标签,但始终不可见。 And the custom-element fucntions does not work. 并且自定义元素功能不起作用。

Try this (for a table with id = myLovelyContainer): 尝试以下操作(对于ID = myLovelyContainer的表):

var elm = document.createElement("tr");
var a = document.createAttribute( "is" );
a.value = "custom-tag";
elm.setAttributeNode(a);
var elm2 = document.createElement("td");
var content = document.createTextNode( "Hello world!" ); 
elm2.appendChild( content );
elm.appendChild( elm2 );
var myLovelyContainer = document.getElementById( 'myLovelyContainer' );
myLovelyContainer.appendChild(elm);

Fiddle: https://jsfiddle.net/tbdycybm/ 小提琴: https//jsfiddle.net/tbdycybm/

Here is the solution 是解决方案

var elm = document.createElement("tr","custom-tag");

I needed mor research but now I am happy :) By this creation way it just acts normal, creates its content and initializez all properties and methods. 我需要研究,但现在我很高兴:)通过这种创建方式,它可以正常工作,创建其内容并初始化所有属性和方法。

I wish polymer has much more detailed tutorials. 我希望Polymer有更多详细的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM