问题
I'm using the <core-list-dart>
element in my Polymer Dart application:
<core-list-dart data="{{data}}">
<template>
<span>{{name}}</span>
</template>
</core-list-dart>
Data is an array of Foo where Foo is:
class Foo {
String name;
...
}
It is possible in the template refer to the Foo instance instead of his fields?
Something like:
<core-list-dart data="{{data}}">
<template>
<foo-element foo="{{ITEM}}"></foo-element>
</template>
</core-list-dart>
回答1:
From version 0.4.0 of core_elements the model is exposed as model
variable in the template.
Old response:
To bind the Item you can use the {{}}
annotation as explained in the @Günter Zöchbauer answer:
<foo-element foo="{{}}"></foo-element>
The problem is that the elements in the array are wrapped by a ListModel class. The "real" element is not accessible (maybe the library can be modified giving this possibility).
The workaround is to put a getter to the model object (Foo) like this:
class Foo {
String name;
Foo get self => this;
...
}
So in the template you can do this:
<foo-element foo="{{self}}"></foo-element>
回答2:
I just tried it and it works.
<foo-element foo="{{}}"></foo-element>
see https://pub.dartlang.org/packages/polymer_expressions - Repeating templates
来源:https://stackoverflow.com/questions/25930606/core-list-dart-template-how-to-bind-to-the-model-itself