简体   繁体   中英

Opening modal in list in Scala HTML

I am trying to open a modal window in a list of items (attachments more specifically) and I cant seem to get the record ID from the list. I open the new modal window with Scala, and I always get error because value record is invalid.

@(recordList: List[assets.Attachment])

@if(recordList == null || recordList.isEmpty()) {
} else {
    <div class="table-responsive">
        <table id="attachment-player-datatable" class="table table-striped 
            table-bordered table-vcenter">
            <thead>
            <tr>
                <th class="text-center"><small>Naziv</small></th>
                <th><small>Datum</small></th>
                <th class="text-center"><small><i class="fa fa-flash"></i></small></th>
            </tr>
            </thead>
            <tbody>
            @for(record <- recordList) {
                <tr id="attachment-@record.getId()">
                    <td><strong><a href="@record.getUrl()">@record.getTitle()</a></strong></td>
                    <td>@record.getFormattedOnlyDate()</td>
                    <td class="text-center">
                        <a id="delete-attachment-action" href="#modal-new-player-attachment" data-toggle="modal" data-id="@record.getId()" class="btn btn-sm btn-danger">
                            <i class="fa fa-trash"></i>
                        </a>
                        <i id="delete-attachment-loader" class="fa fa-spinner 
                       fa-2x fa-spin text-primary" style="display:none;"></i>
                    </td>
                </tr>
            }
            </tbody>
        </table>
    </div>
}
@playerFolder.attachmentRemoveModal(record.getId())

I believe your error is being caused by this line:

@playerFolder.attachmentRemoveModal(record.getId())

This reference to record is outside the for loop it is defined in ( @for(record <- recordList) {...} ). You can't reference variables outside where they are defined (without importing or doing something similar... not applicable here). For example:

scala> val list = List(1, 2, 3)
list: List[Int] = List(1, 2, 3)

scala> for (elem <- list) {
     |   println(elem)
     | }
1
2
3

scala> elem
<console>:12: error: not found: value elem
       elem
       ^

In this scenario, elem is only available inside the for loop. If you try to reference it outside the loop, the compiler doesn't know what you're trying to reference and complains.

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