I have a custom data type in Dart that I would like to make iterable with template repeat. The following are truncated versions of data types:
class Note {
String content;
Note(this.content);
}
class Notebook {
List<Note> notes;
Notebook(this.notes);
}
I want to be able to iterate through Noteto Notebooklike this:
<polymer-element name="x-notebook=view">
<ul>
<template repeat="{{note in notebook}}">
<li is="x-note-view" note="{{note}}></li>
</template>
</ul>
<script ...></script>
</polymer-element>
The problem, of course, is that the standard Listcan be repeated in this way, but I'm not sure how to change my own data type Notebookto do the same.
One way that seems to work is to attach the method toList()to the class Notebook:
List<Note> toList() => notes;
But I was hoping to make this possible without first converting to List.