如何从 handlebarsjs 访问这个 json 对象 [英] How to access this json object from handlebarsjs

查看:21
本文介绍了如何从 handlebarsjs 访问这个 json 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从handlebarsjs访问这个json对象

How to access this json object from handlebarsjs

    [ {
    "id" : 9,
    "name" : "Name1",
    "address" : "address1",
    "city" : "city1",
    "state" : "KS",
    "zip" : "11111",
    "country" : "USA",
    "fax" : "111111",
    "phone" : "1111111",
    "website" : "",
    "account" : "11111",
    "contacts" : []
}, {
    "id" : 12,
    "name" : "Name2",
    "address" : "address2",
    "city" : "city2",
    "state" : "NJ",
    "zip" : "11111",
    "country" : "USA",
    "fax" : "",
    "phone" : "1111",
    "website" : "",
    "account" : "11111",
    "contacts" : [ {
        "firstName" : "name",
        "lastName" : "lastname",
        "title" : "rep",
        "phone" : "3333",
        "email" : "33333"
    } ]
} ]

我尝试过 {{name}} 访问姓名,但没有成功,那么我如何访问姓名属性,以及联系人下嵌套的 firstName 属性?

I have tried {{name}} to access name but that didn't work, so how do i access name attribute, and the nested firstName attribute under contacts?

谢谢

推荐答案

你很幸运:你的问题在 Handlebars 文档页面上解释得很清楚:

You're in luck: your question is explained pretty clearly on the Handlebars documentation page:

http://handlebarsjs.com/

只需向下滚动到Handlebars Paths"部分,您就会看到它准确地说明了您正在寻找的内容(Handlebars 还支持嵌套路径,从而可以查找嵌套在当前上下文下方的属性...")

Just scroll down to the "Handlebars Paths" section, and you'll see it talks about exactly what you're looking for ("Handlebars also supports nested paths, making it possible to look up properties nested below the current context ...")

这篇关于如何从 handlebarsjs 访问这个 json 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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