如何以聚合物表示法绑定(bind)到 json 对象内的键/值对。我有模板重复=“{{jsonarray中的对象}}”...我想布置一个表格。假设每个对象有 {1: 一, 2: 二, 3: 三}
类似于:
<template repeat="{{item in mylist}}">
<tr>
<template repeat="{{key, value in item}}">
<td>{{key}}: {{value}}</td>
</template>
</tr>
</template>
最佳答案
这段代码对我有用:
Dart :
@observable List jsonlist = toObservable(JSON.decode('[{"1":"one"},{"2":"two"}]'));
HTML:
<template repeat="{{ foo in jsonlist }}">
{{ foo }}
<template repeat="{{ key in foo.keys }}">
{{ key }} = {{ foo[key] }}
</template>
</template>
使用此代码我得到以下输出:
{1: one} 1 = one {2: two} 2 = two
问候 罗伯特
关于dart - 将JSON键值对绑定(bind)到polymer dart中的表模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23450520/