core-list-dart template how to bind to the model itself

為{幸葍}努か 提交于 2020-01-05 03:51:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!