简体   繁体   中英

json2html, calling JSON data in an array

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'
    }
]}

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) );
}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM