如何使用车把模板显示json对象的键和值? [英] how to show json object key and value using handlebar template?

查看:130
本文介绍了如何使用车把模板显示json对象的键和值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始学习handlebar.js。我正在努力显示json数据。

I have started to learn handlebar.js . I am struggling to display json data .

我的json看起来像这样:

My json look like this:

 var data={
          "record1":
          [
             {
               "first":
                      [
                       {
                         "name":"john",
                         "city":"newyork"  
                       },
                       {
                         "name":"britto",
                         "city":"bangalore"  
                       }
                      ]
             },
            {"second":
                 [
                  {
                    "name":"franklin",
                    "city":"newyork"  
                  },
                  {
                    "name":"leo",
                    "city":"bangalore"  
                  }
                ]
            }
        ]
    };

这里这个json来自服务器响应,所以我不知道任何键和值。我必须通过使用手柄来动态显示键和值...我已经尝试过使用每个键,但是我没有解决这个问题。任何人都可以帮助我吗?

here this json is coming from server response so I don't know any key and value. I have to show key and value dynamically by using handlebar ...I have tried with eachKey but I have not got solution for that . Can anyone help me?

推荐答案

您可以像下面这样在Handlebars模板中呈现列表的键/值:

You can render the keys/values of a list in a Handlebars template like this:

{{#each object}}
  {{@key}}: {{this}}
{{/each}}

这篇关于如何使用车把模板显示json对象的键和值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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