简体   繁体   English

json2html,在数组中调用JSON数据

[英]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: 我正在使用json2html并试图找出在数组中调用JSON数据的正确语法:

{ 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. 在其他情况下,我使用了类似{“ tag”:“ div”,“ html”:“ $ {biographicData.firstName}”}的值来获取值,但是当数据在其中时似乎不起作用数组。 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) );
}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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