Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Polymer 动态添加铁名单和所有铁名单';s数据_Polymer_Dart - Fatal编程技术网

Polymer 动态添加铁名单和所有铁名单';s数据

Polymer 动态添加铁名单和所有铁名单';s数据,polymer,dart,Polymer,Dart,我遇到了一个我无法解决的问题。我需要从代码中添加元素,分配其项,等等 我已经在谷歌上搜索了好几天了,但在我发现的所有示例中,都是用HTML添加的 我试过这个: 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("templ

我遇到了一个我无法解决的问题。我需要从代码中添加
元素,分配其项,等等

我已经在谷歌上搜索了好几天了,但在我发现的所有示例中,
都是用HTML添加的

我试过这个:

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);
var list=new Element.html(“[[item.text]]”);
listTab.children.add(列表);
错误:

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

Polymer::Attributes:无法将数组解码为JSON
正在从[object DocumentFragment]中删除不允许的元素
正在从[object DocumentFragment]中删除不允许的元素
从铁清单中删除不允许的元素
未捕获的未处理异常:
错误状态:无元素
如果能从dart代码中添加
元素,我将不胜感激

var validator=new NodeValidatorBuilder.common()
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);
…allowElement('iron-list',属性:['items','as'] …合金化(…); var list=new Element.html(“[[item.text]]”, 验证器:验证器); listTab.children.add(列表);

var list=new Element.html(“[[item.text]]”,
TreeSInitiatizer:NodeTreeSanitizer.trusted);
listTab.children.add(列表);

谢谢,两种解决方案都有效!但我仍然得到错误:
Polymer::Attributes:cand
t将数组解码为JSON`
Polymer::Attributes:canoldnt将数组解码为JSON
item.innerHtml=“[[item.text]]”不会创建绑定。尝试一下
item.innerHtml=item.text您的错误消息可能来自其他原因。我认为我添加的列表作为铁名单的数据存在一些问题。至少,它们都没有出现。我会尽力找出问题:)你说得对。我已经在呈现列表的其他函数中指定了铁元素列表项,它可以正常工作。我非常感谢你的帮助!谢谢!
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);