テンプレートを使用してオブジェクトのリストからツリーを作成しようとしていますが、うまくいきません。より良い方法があれば、私もそれに興味があります。
エラーなしで実行されますが、何も表示されません。
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,[]));
}
私は何を間違っていますか?
どうもありがとう