我正在尝试使用模板从对象列表中创建一棵树,但我无法让它工作。如果有更好的方法我也对它感兴趣。
它运行没有错误,但没有显示任何内容。
这是html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="packages/polymer/boot.js"></script>
</head>
<body>
<ul>
<template id="tmpl" repeat="{{ getRoot() }}">
<li>{{ name }}
<ul>
<template ref="tmpl" repeat="{{ getChildren(name) }}"></template>
</ul>
</li>
</template>
</ul>
<script type="application/dart" src="test2.dart"\>
</body>
</html>
还有飞镖文件:
import 'package:polymer/polymer.dart';
class Item extends ObservableBase {
@observable String name;
@observable List<String> children;
@observable int level;
Item(this.name, this.level, this.children);
}
@observable List<Item> items;
List<Item> getRoot(){
return items.where((t) => t.level == 0);
}
List<Item> getChildren(String name){
Item item = items.singleWhere((t) => t.name == name);
return items.where((t) => item.children.contains(t.name));
}
main() {
items = new List();
items.add(new Item('Smurfs',0,['Smurf1','Smurf2']));
items.add(new Item('Smurf1',1,[]));
items.add(new Item('Smurf2',1,[]));
}
我究竟做错了什么?
非常感谢