json2html,在数组中调用JSON数据 [英] json2html, calling JSON data in an array

查看:122
本文介绍了json2html,在数组中调用JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用json2html并试图找出在数组中调用JSON数据的正确语法:

I'm using json2html and trying to figure out the correct syntax for calling JSON data within an array:

{ biographicData: [
    {
        firstName: 'John',
        lastName: 'Doe',
        birthDate: '10/15/1983',
        email: 'johndoe@gmail.com',
        workPhone: '678-901-2345',
        mobilePhone: '098-765-4321',
        homePhone: '123-456-7890'
    }
]}

在其他情况下,我使用了类似{"tag":"div","html":"$ {biographicData.firstName}"}的值来获取值,但是当数据在一个数组中.我该怎么做才能解决此呼叫?

In other cases, I've used something like {"tag":"div","html":"${biographicData.firstName}"} to get the values, but that doesn't seem to work when the data is in an array. What do I need to do to fix this call?

推荐答案

要访问数组数据,如果知道要访问的数组的位置,则可以执行以下操作

To access array data you can do something like this if you know the position of the array you are trying to access

{"tag":"div","html":"${biographicData.0.firstName}"}

或者您可以使用内联函数和变换来变换整个数组(如果有多个元素)

or you could transform the entire array (if there are multiple elements) using an inline function and a transform

{"tag":"div","children":function(){
   return( json2html.transform(this,bioDataTransform) );
}}

这篇关于json2html,在数组中调用JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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