我的源代码是
<div>
<h1>
Music track</h1>
<form id="filter">
<input type="text" [(ngModel)]="term" name="search" />
</form>
<table border="1" class="mytab">
<tr>
<ul class="list-group">
<li class="list-group-item" *ngFor="let item of tracks|filter:term">
{{item.title}}
<div *ngFor="let genre of tracks.genres">
{{tracks.genres?.tracks.genres.name}}
</div>
{{item.rating}}
</li>
</ul>
</tr>
</table>
<button id="add new track" name="add" (click)="addnew()">Add New Track</button>
</div>
它会抛出错误:
.modal-body
=render 'folders/pieces/update', id: @piece , folder_id: @piece.folder_id
我想在渲染页面中传递两个参数
答案 0 :(得分:4)
您的代码有效且正确 - 这正是您传递多个参数以进行渲染的方式。
错误来自{
"data":[
{
"id":"27",
"type":"visit",
"attributes":{
"address-id":"82",
"client-id":"26",
"care-service-id":"2",
"carer-id":"",
"care-service":"Domiciliary care",
"brief":null,
"starts-at":"2017-03-03T12:12:00+00:00",
"ends-at":"2017-03-03T14:14:00+00:00",
"checked-in-at":null,
"checked-out-at":null,
"checkout-notes":null,
"state":"unallocated",
"care-plan-summary":"",
"pay-rate":12.0,
"pay-rate-currency":"GBP"
},
"relationships":{
"address":{
"data":{
"id":"82",
"type":"address"
}
},
"client":{
"data":{
"id":"26",
"type":"client"
}
}
}
},
{
"id":"28",
"type":"visit",
"attributes":{
"address-id":"112",
"client-id":"46",
"care-service-id":"2",
"carer-id":"",
"care-service":"Domiciliary care",
"brief":null,
"starts-at":"2017-03-04T12:12:00+00:00",
"ends-at":"2017-03-04T14:14:00+00:00",
"checked-in-at":null,
"checked-out-at":null,
"checkout-notes":null,
"state":"unallocated",
"care-plan-summary":"",
"pay-rate":14.0,
"pay-rate-currency":"GBP"
},
"relationships":{
"address":{
"data":{
"id":"112",
"type":"address"
}
},
"client":{
"data":{
"id":"46",
"type":"client"
}
}
}
},
... etc ...
],
"included":[
{
"id":"26",
"type":"client",
"attributes":{
"title":"Ms",
"first-name":"Jessica",
"middle-name":null,
"last-name":"Rabbit",
"preferred-name":null,
"primary-phone":"555-909-9555",
"secondary-phone":null,
"email":"jessica.rabbit@example.com",
"date-of-birth":"1985-10-14",
"marital-status":"Single",
"gender":"Female",
"nationality":"British",
"ethnicity":"Human",
"religion":"N/A",
"care-plan-summary":null,
"photo-url":"/images/client_26.png",
"allergies":[
],
"care-requirements":[
"Domiciliary care"
],
"medical-conditions":[
],
"interests":[
],
"pets":[
],
"skill-requirements":[
]
},
"relationships":{
"addresses":{
"data":[
{
"id":"82",
"type":"address"
}
]
}
}
},
{
"id":"46",
"type":"client",
"attributes":{
"title":"Mr",
"first-name":"Donald",
"middle-name":null,
"last-name":"Duck",
"preferred-name":null,
"primary-phone":"555-779-1875",
"secondary-phone":null,
"email":"donald.duck@example.com",
"date-of-birth":"1955-10-14",
"marital-status":"Single",
"gender":"Male",
"nationality":"British",
"ethnicity":"Duck",
"religion":"N/A",
"care-plan-summary":null,
"photo-url":"/images/client_46.png",
"allergies":[
],
"care-requirements":[
"Domiciliary care"
],
"medical-conditions":[
],
"interests":[
],
"pets":[
],
"skill-requirements":[
]
},
"relationships":{
"addresses":{
"data":[
{
"id":"112",
"type":"address"
}
]
}
}
},
... etc ...
],
"links":{
},
"meta":{
"page-size":10,
"page-number":1,
"total-pages":1
}
}
为@piece
。
答案 1 :(得分:-2)
您的代码对于多个参数绝对正确。该错误是因为您在nil
中获得@piece
值。
您可以按如下方式处理nil
值:
@piece.try(:folder_id)
您的代码将类似于:
.modal-body =render 'folders/pieces/update', id: @piece , folder_id: @piece.try(:folder_id)
如果nil
值,则不会抛出任何错误。