json2html, calling JSON data in an array

假装没事ソ 提交于 2020-01-05 04:02:08

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/20382132/json2html-calling-json-data-in-an-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!