使用pdfobject将pdf放在模态引导程序中 - 递增文件

问题描述 投票:0回答:1

我正在尝试在模态引导程序中进行pdf显示。我在我的应用程序中使用数据表,我的表头由文档标题,类别,日期和文档视图组成。在View Document列的主体中,我有一个按钮,当用户单击一个模态时,它会打开并在其中打开pdf。

我表中的每一行都有一个不同的pdf文档,这是我的问题,我无法将pdf引用到各自模式中的每一行。在任何一行打开的pdf始终是我表格中添加的最后一个文档。

在那个应用程序中我使用firebase,pdfobject插件为模态添加pdf和bootstrap。

我的代码如下:

使用Javascript:

<script type="text/javascript">
    var documentosRef = firebase.database().ref('documentos');

    function initFirebase(){

        function carregaDocumentos(){

            documentosRef.on('value', function(data){

                headertb = isAdmin ? "<th>Título</th><th>Data de Inclusão</th><th>Categoria</th><th>Editar</th><th>Excluir</th>" : "<th>Título</th><th>Data de Inclusão</th><th>Categoria</th><th>Visualizar</th>";

                $('#tableCustom thead tr').html(headertb);


                $("#tableCustom").dataTable().fnDestroy();
                $('#tableCustom tbody').html('');

                for(var key in data.val()){

                    documento = data.val()[key]

                    if(isAdmin){
                        linha = "<tr>"+
                                    "<td>"+documento.titulo+"</td>"+
                                    "<td>"+documento.data_inicio+"</td>"+
                                    "<td>"+documento.categoria+"</td>"+
                                    "<td class='edit'><a href='documentos/"+key+"/edit'><i class='fa fa-edit'></i></a></td>"+
                                "</tr>";
                        $('#tableCustom tbody').append(linha);
                    }
                    else{

                        linha = "<tr>"+
                                    "<td>"+documento.titulo+"</td>"+
                                    "<td>"+documento.data_inicio+"</td>"+
                                    "<td>"+documento.categoria+"</td>"+
                                    "<td class='view'><a data-toggle='modal' data-target='#myModal'><i class='fa fa-eye'></i></a></td>"+
                                "</tr>";
                        $('#tableCustom tbody').append(linha);  
                        PDFObject.embed(documento.arquivo, ".modal-content");
                    }
                }

                closeLoader();

                 var table = $('#tableCustom').DataTable({
                    "aaSorting": [[ 0, "asc" ]],
                     "oLanguage": {
                        "sUrl": "/datatable_pt.txt"
                    },
                    "aoColumnDefs": [
                        { "bSortable": true, "aTargets": [ 0 ] },
                        { "bSearchable": true, "aTargets": [ 0, 1, 2 ] }
                    ]
                 });

                $("#select-categories").each( function ( i ) {
                    var select = $('<select><option value=""></option></select>')
                        .appendTo( $(this).empty() )
                        .on( 'change', function () {
                            table.column( [2] )
                                .search( $(this).val() )
                                .draw();
                        } );

                    table.column([2]).data().unique().sort().each( function ( d, j ) {
                        select.append( '<option value="'+d+'">'+d+'</option>' )
                    } );
                } );

            });

        }

        carregaDocumentos();
    }
</script>

HTML:

    <div id="body">
        <header>
            Documentos
        </header>
        <section>

        <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">
                <div class="modal-content">
                </div>
            </div>
        </div>

        <table id="tableCustom">
            <div id="select-categories"></div>
            <thead>
                <tr>

                </tr>
            </thead>
            <tbody>
            <!--oddloop-->

            <!--oddloop-->
            </tbody>
        </table>
    </section>
</div>
javascript jquery firebase pdf pdfobject
1个回答
1
投票

您正在将文档嵌入到for循环中每行的单个模式中。在每次迭代之后,嵌入在模态中的先前文档被覆盖,因此导致最后一个文档是唯一可见的文档。

在单击视图按钮时,应该使用嵌入的文档填充模态,而不是在加载时填充模态。这可以通过将documento.arquivo作为数据属性添加到相应行的模态切换按钮来完成。

© www.soinside.com 2019 - 2024. All rights reserved.