简体   繁体   中英

Jade not rendering external JSON

I have a jade template that should list all possible solutions to the QPX Express search request:

{ kind: 'qpxExpress#tripsSearch',
  trips: 
   { kind: 'qpxexpress#tripOptions',
     requestId: 'RwDOf6HXVDvvn6nBm0PNpw',
     data: 
      { kind: 'qpxexpress#data',
        airport: [Object],
        city: [Object],
        aircraft: [Object],
        tax: [Object],
        carrier: [Object] },
     tripOption: [ [Object], [Object], [Object] ] } }

However, I'm trying to render the above the view but I keep getting this error:

Cannot read property 'tripOption' of undefined

Template

block content
  .ui
    for data in result
      .ui_box
        .ui_box__inner
          .event
            span #{data.trips.tripOption[].saleTotal}

Route

router.get('/', function(req, res, next) {
  api.apiGet(function (data) {
    console.log(data) //THIS WORKS
    res.render('index', {result: data})
  })
})

All the code is looking right to me and I'm working off properties from the API documentation . Can anyone point me in the right direction to debug?

Update: 1

To display saleTotal from array of tripOption , change your jade template like the below one,

block content
  .ui
    for data in result
      .ui_box
        .ui_box__inner
          .event
            each trip in data.trips.tripOption
            span #{trip.saleTotal}

In your code, span #{data.trips.tripOption[].saleTotal}

if data refers to JSON content then change your span bindings like this

span #{data.trips.data.tripOption[].saleTotal} else span #{data.tripOption[].saleTotal}

Because tripOption is avaiable in data object not in trips

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