Dart 在省道聚合中嵌套在另一聚合中

Dart 在省道聚合中嵌套在另一聚合中,dart,polymer,dart-polymer,Dart,Polymer,Dart Polymer,我正试着在另一个类似这样的聚合体中嵌套Dart聚合体 @CustomTag('test-box') class Box extends PolymerElement{ @observable List<Child> childs = new List<Child>(); Box.created() : super.created() { } } @CustomTag('test-child') class Child extends PolymerEl

我正试着在另一个类似这样的聚合体中嵌套Dart聚合体

@CustomTag('test-box')
class Box extends PolymerElement{
    @observable List<Child> childs = new List<Child>();

    Box.created() : super.created() { }
}

@CustomTag('test-child')
class Child extends PolymerElement{
    Child.created() : super.created() { }
}
@CustomTag('test-box'))
类框扩展了关联{
@可观察列表childs=新列表();
Box.created():super.created(){}
}
@CustomTag('test-child')
类子关系{
Child.created():super.created(){}
}
然后在testbox.html中

<link rel="import" href="testchild.html">
<polymer-element name="test-box">
  <template>
    <div>
      <ol name="child-list">
        <template repeat="{{child in childs}}">
          {{child}}
        </template>
      </ol>
    </div>
  </template>
  <script type="application/dart" src="testbox.dart"></script>
</polymer-element>

{{child}}
用Dart/聚合物可以吗?我所有的尝试都失败了。 我想像处理类一样处理html节点


提前感谢

您可以使用模型对象通过发布的属性将数据传递给子元素


选中此示例:

您可以将子节点添加到该框中,例如:

@CustomTag('test-box') 
class Box extends PolymerElement{
@observable List<Child> childs = new List<Child>();

    Box.created() : super.created() { 

    }

    void _addChildren(List<Child> children) {
        children.forEach((Child c) {
           this.children.add(c);
        }  
    }

    @override void attached() { super.attached(); _addChildren(childs); }
}
@CustomTag('test-box'))
类框扩展了关联{
@可观察列表childs=新列表();
Box.created():super.created(){
}
void\u addChildren(列出子项){
儿童。forEach((儿童c){
本条.儿童.加入(c);
}  
}
@重写void attached(){super.attached();_addChildren(childs);}
}
然后,您可以使用
observable
API监视child上的更改,以反映阵列上的更改

请注意,应该使用
新元素.tag(“测试子项”)
创建
子对象


但是,最好的解决方案是@Leksat使用更纯粹的MVC方法提供的解决方案。

我遇到了几乎相同的问题,并使用某种代理元素解决了它。 ProxyElement Dart代码:

library ProxyElement;

import 'package:polymer/polymer.dart';

@CustomTag('proxy-element')
class ProxyElement extends PolymerElement {

  @published PolymerElement target;

  ProxyElement.created() : super.created();

  attached() {
    shadowRoot.querySelector('#proxy').append(target);
  }

}
及其HTML代码:


:主持人{
显示:内联;
}
没有定义目标元素。
用法:

...
<template repeat="{{child in children}}">
    <proxy-element target="{{child}}"></proxy-element>
</template>
...
。。。
...

链接元素必须位于聚合元素内。另外,{{child}是一个表达式,您需要一个标记:。请参阅许多示例。实际上,这不起作用。它将为每个列表项插入一个新的测试子元素,但这不是列表中的项。这是一个可行的解决方案,但不是我所希望的。在JS中,存储/创建非嵌入html节点没有问题。目前似乎没有另一种是dart聚合物。
...
<template repeat="{{child in children}}">
    <proxy-element target="{{child}}"></proxy-element>
</template>
...