2017-09-14 260 views
0

我尝试使用vueJS v-for函数遍历多维json_object。Vuejs v-for multidimensional array json_object

,但我得到以下错误:

[Vue warn]: Error in render function: "TypeError: Cannot read property 'id' of null"

我的代码如下所示:

    <tr v-for="timeblock in responseAPI"> 
          <td> 
          {{timeblock.time}} 
          </td> 
          <td v-for="value in timeblock.appointment"> 
          {{value.id}} 
          </td> 
          <td> 
          {{timeblock.break}} 
          </td> 
          <td> 
          {{timeblock.scheduled}} 
          </td> 
          <td> 
          {{timeblock.text}} 
          </td> 
         </tr> 

而且我JSON_OBJECT这样的:

[ 
    { 
    "time": "09:00", 
    "break": null, 
    "scheduled": "Stoel 1", 
    "appointment": { 
     "id": 1, 
     "patient_id": 1, 
     "chair_id": 1, 
     "date": "2017-05-10", 
     "time": "09:00:00", 
     "duration": 30, 
     "treatment_type": "Controle", 
     "created_at": null, 
     "updated_at": null 
    }, 
    "text": null 
    }, 
    { 
    "time": "09:30", 
    "break": null, 
    "scheduled": "Stoel 1", 
    "appointment": { 
     "id": 2, 
     "patient_id": 2, 
     "chair_id": 1, 
     "date": "2017-05-10", 
     "time": "09:30:00", 
     "duration": 30, 
     "treatment_type": "Controle ", 
     "created_at": null, 
     "updated_at": null 
    }, 
    "text": null 
    } ] 

回答

0

当V-的对象的值是你不需要访问任何道具,因为该值不是一个键/值,但价值仅

<td v-for="value in timeblock.appointment"> 
     {{value}} 
    </td> 
+0

那么简单,thnks每个键的值! –

0

timeblock.appointment不是一个数组但只是一个普通的对象。尝试

<td> 
    {{timeblock.appointment.id}} 
</td>