core-list-dart模板如何绑定到模型本身 [英] core-list-dart template how to bind to the model itself
问题描述
我在我的Polymer Dart应用程序中使用< core-list-dart>
元素:
< core-list-dart data ={{data}}>
< template>
< span> {{name}}< / span>
< / template>
< / core-list-dart>
数据是Foo的数组,其中Foo是:
class Foo {
String name;
...
}
在模板中可以参考
< core-list-dart data ={{data}}>
< template>
< foo-element foo ={{ITEM}}>< / foo-element>
< / template>
< / core-list-dart>
版本 0.4.0 of the core_elements the model is exposed as model
variable in the template。
旧响应:
要绑定项目,您可以使用 {{}}
注释,如@GünterZöchbauer回答:
< foo-element foo ={ {}}>< / foo-element>
问题是数组中的元素被ListModel类包装。 真正的元素是不可访问的(也许库可以修改给予这种可能性)。
解决方法是把一个getter到模型对象this:
class Foo {
String name;
Foo get self =>这个;
...
}
所以在模板中你可以这样做:
< foo-element foo ={{self}}> foo-element>
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>
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>
这篇关于core-list-dart模板如何绑定到模型本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!