我正在研究我的第一个聚合物应用程序,但我被卡住了。如何使用聚合物访问地图值?我有一堂课,里面有一张地图。我可以遍历模板中的列表,但是如何从地图中获取所有值?
query('#tmpl-question').model = q;
query('#tmpl-answers').model = q.map_answers;
@observable
class Question extends PolymerElement with ObservableMixin{
@observable
Map<String,String> map_answers = toObservable({}); //new Map<String,String>();
void initQuestion(){
map_answers["false1"]="1";
map_answers["true"]="42";
map_answers["false2"]="2";}}
<template id="tmpl-answers" repeat>
<p>
<label for"a1" value="asdf"> HOW TO DISPLAY ALL MAP VALUES //iterate over list elements with {{}}
</p>
</template>
编辑:问题在于将对象分配q
给模型。
不起作用:
Question q = new Question();
query('#tmpl-question').model = q;
如果你导入'package:polymer_expressions/polymer_expressions.dart';这将起作用:
TemplateElement template = query('#tmpl-question');
template.bindingDelegate = new PolymerExpressions(globals: {
'uppercase': (String input) => input.toUpperCase()
});
template.model = q;
.
<template repeat="{{j in map2.keys}}">
<li>{{map2[j]}}</li>
</template>