我遇到了一个我无法解决的问题。我需要从代码中添加<iron-list>元素,分配它的项目等等。
我已经用谷歌搜索了好几天,但是在所有的例子中,我发现<iron-list>已经被添加到超文本标记语言中了。
我试过了:
var msgs = new List();//I've added some data to this list
var listTab = new Element.div();
var list = new Element.tag("iron-list");
var template = new Element.tag("template");
var item = new Element.tag("paper-item");
item.innerHtml = "[[item.text]]";
template.children.add(item);
list.children.add(template);
list.items = msgs;
list.as = "item";
listTab.children.add(list);这会导致以下错误:
iron-list requires a template to be provided in light-dom
Uncaught Unhandled exception:
TypeError: this.ctor is not a function下面的代码会导致相同的错误:
var msgs = new List();//I've added some data to this list
var listTab = new Element.div();
IronList list = new IronList();
var template = new Element.tag("template");
var item = new Element.tag("paper-item");
item.innerHtml = "[[item.text]]";
template.children.add(item);
list.children.add(template);
list.items = msgs;
list.as = "item";
listTab.children.add(list);最后,我尝试了一个非常简单的解决方案,它也不起作用:
var list= new Element.html('<iron-list items="{{msgs}}" as="item"><template><paper-item>[[item.text]]</paper-item></template></iron-list>');
listTab.children.add(list);错误:
Polymer::Attributes: couldn`t decode Array as JSON
Removing disallowed element <IRON-LIST> from [object DocumentFragment]
Removing disallowed element <PAPER-ITEM> from [object DocumentFragment]
Removing disallowed element <ARRAY-SELECTOR> from iron-list
Uncaught Unhandled exception:
Bad state: No element我真的很感激从dart代码中添加<iron-list>元素的有效解决方案。
发布于 2017-02-26 18:14:39
var validator = new NodeValidatorBuilder.common()
..allowElement('iron-list', attributes: ['items', 'as'])
..allowElement(...);
var list= new Element.html('<iron-list items="{{msgs}}" as="item"><template><paper-item>[[item.text]]</paper-item></template></iron-list>',
validator: validator);
listTab.children.add(list);或
var list= new Element.html('<iron-list items="{{msgs}}" as="item"><template><paper-item>[[item.text]]</paper-item></template></iron-list>',
treeSanitizer: NodeTreeSanitizer.trusted);
listTab.children.add(list);https://stackoverflow.com/questions/42466747
复制相似问题