在聚合物dart中将JSON键值对绑定到表模板 [英] Bind JSON key value pairs to table template in polymer dart

查看:148
本文介绍了在聚合物dart中将JSON键值对绑定到表模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绑定到聚合符号中的json对象中的键/值对。我有模板repeat ={{objects in jsonarray}}...我想布置一个表。说每个对象都有{1:1,2:2,3:3}

how I can bind to the key/value pairs within a json object in polymer notation. i have template repeat="{{objects in jsonarray}}"... I want to lay out a table. say each object has {1: one, 2: two, 3: three}

<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>

使用此代码,我得到以下输出:

With this code I get the following output:


{1:one} 1 =一个{2:two} 2 =两个

{1: one} 1 = one {2: two} 2 = two



<
Robert

Regards Robert

这篇关于在聚合物dart中将JSON键值对绑定到表模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆