2016-12-26 82 views
-1

我在JSON中有兩個包含以下內容的表。v-for插入第二個v-爲子

第一個表:

[ 
   {"Id": "1", "name": "Joe"}, 
    {"Id": "2", "name": "Mark"} 
] 

二表:

[ 
    {"Student": "1", "note": "5", "assessment": "1"}, 
    {"Student": "1", "note": "6", "assessment": "2"}, 
    {"Student": "1", "note": "7", "assessment": "3"}, 
    {"Student": "1", "note": "8", "assessment": "4"}, 
    {"Student": "2", "note": "3", "assessment": "1"}, 
    {"Student": "2", "note": "5", "assessment": "2"}, 
    {"Student": "2", "note": "8", "assessment": "3"}, 
    {"Student": "2", "note": "9", "assessment": "4"} 
] 

如何使這樣的數據

Student: Jose 
Evaluation 1 | Note 5 
Evaluation 2 | Note 6 
Evaluation 3 | Note 7 
Evaluation 4 | Note 8 

Student: Mark 
Evaluation 1 | Note 3 
Evaluation 2 | Note 5 
Evaluation 3 | Note 8 
Evaluation 4 | Note 9 

我使用的V-資源消耗每GET JSON我可以製作第一張專輯

<Div v-for = "student in students"> 
    Student {{student.name}} 
    ??? 
</ Div> 

將第二個與學生關聯的最好方法是什麼?

回答

0
<Div v-for = "student in students"> 
     Student: {{student.name}} 
     <Div v-if ="note.Student == student.Id" v-for = "note in notes"> 
     Note {{note.note}} | Assessment {{ note.assessment}}   
     </Div> 

</Div>