如何在Dart Polymer中使用和迭代可观察的地图? [英] How to use and to iterate an observable map in Dart Polymer?
本文介绍了如何在Dart Polymer中使用和迭代可观察的地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下代码:
myexample.html
< polymer-element name =my-example>
< script type =application / dartsrc =myexample.dart>< / script>
< template>
< style>< / style>
< div>
< ul>
< template repeat ={{map invalues}}>
< li> {{entry}}< / li>
< / template>
< / ul>
< button on-click ={{add}}>添加< / button>
< / div>
< / template>
< / polymer-element>
myexample.dart
$ b b< b>< int>< int>< int> map = toObservable({});
int i = 0;
MyExample.created():super.created();
void add(){
map [i ++] = i.toString();
}
}
按钮,但映射条目不会显示在myexample.html中。所以:如何正确地使用(和迭代)可观察映射,以便html文件中的列表自动更新?
解决方案
这是一个错误。我刚刚提出:
https://code.google.com/p/dart/issues/detail?id=15407
请将问题标上星号,以便您可以在修复错误时通知。
Consider the following code:
myexample.html
<polymer-element name="my-example">
<script type="application/dart" src="myexample.dart"></script>
<template>
<style></style>
<div>
<ul>
<template repeat="{{ entry in map.values }}">
<li>{{ entry }}</li>
</template>
</ul>
<button on-click="{{add}}">Add</button>
</div>
</template>
</polymer-element>
myexample.dart
@CustomTag('my-example')
class MyExample extends PolymerElement {
@observable Map<int, String> map = toObservable({});
int i = 0;
MyExample.created() : super.created();
void add() {
map[i++] = i.toString();
}
}
The map is filled on every click of the "Add" button, but the map-entries aren't shown in myexample.html. So: How to use (and to iterate) an observable Map properly, such that the list in the html-file is updated automatically?
解决方案
This is a bug. I just filed it:
https://code.google.com/p/dart/issues/detail?id=15407
Please star the issue so that you can be notified when the bug is fixed.
这篇关于如何在Dart Polymer中使用和迭代可观察的地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文