2016-02-27 46 views
0

調用時出現此錯誤是沒有定義:length not defined這段代碼運行在玉時:長度玉

each time in appointment.location.openingTimes 
     p 
      | #{time.days}: 
      if time.closed 
      span.pull-right.badge-default closed 
      else 
      span.pull-right.badge-default #{time.opening} - #{time.closing} 

它引用數組:

appointment: { 
     reason: 'Johnny to Busby3', 
     location: [{ 
      name: 'Buga Buga Hospital', 
      phoneNumber: '(719) 589-1011', 
      address: { 
       street: '125 High Street', 
       region: 'Buga Buga, HI 85555', 
      }, 
      distance: '100m', 
      coords: { 
       lat: 51.455041, 
       lng: -0.9690884 
      }, 
      openingTimes: [{ 
       days: 'Monday - Friday', 
       opening: '7:00 am', 
       closing: '7:00 pm', 
       closed: false 
      }, { 
       days: 'Saturday', 
       opening: '8:00 am', 
       closing: '5:00 pm', 
       closed: false 
      }, { 
       days: 'Sunday', 
       closed: true 
      }], 
     }], 

我想有一些命名問題正在進行,但我找不到它們。

+0

位置是一個數組,所以你不能用一個點訪問訪問openingTimes(位置是有openingTimes財產對象的數組),所以你需要兩個循環或重組數據 –

回答

1

簡單。 location數組裏面有一個對象。

use appointment.location[0].openingTimes

+0

非常感謝你給這個嘗試! – KyleRiggen

+0

不客氣! –

0

appointment.location也是一個數組。

爲了達到內的物體,它具有openingTimes,你必須訪問索引:

each time in appointment.location[0].openingTimes 
    # ... 

您還可以重複appointment.location以及openingTimes

each location in appointment.location 
    each time in location.openingTimes 
     # ... 
+0

優秀。給這個嘗試! – KyleRiggen