Javascript 将pdf与pdfobject一起放置在模式引导中-递增文件

Javascript 将pdf与pdfobject一起放置在模式引导中-递增文件,javascript,jquery,firebase,pdf,pdfobject,Javascript,Jquery,Firebase,Pdf,Pdfobject,我正在尝试在模式引导中显示pdf。我在应用程序中使用datatables,表的标题由文档标题、类别、日期和文档视图组成。在“查看文档”列的主体中,我有一个按钮,当用户单击某个模式时,该按钮将打开,其中的pdf也将打开 我表格中的每一行都有一个不同的pdf文档,这是我的问题,我无法将引用每一行的pdf放在其各自的模式中。在任何一行打开的pdf始终是添加到我的表中的最后一个文档 在该应用程序中,我使用firebase,pdfobject插件为模式添加pdf和引导 我的代码如下: Javascript

我正在尝试在模式引导中显示pdf。我在应用程序中使用datatables,表的标题由文档标题、类别、日期和文档视图组成。在“查看文档”列的主体中,我有一个按钮,当用户单击某个模式时,该按钮将打开,其中的pdf也将打开

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

在该应用程序中,我使用firebase,pdfobject插件为模式添加pdf和引导

我的代码如下:

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>

var documentosRef=firebase.database().ref('documentos');
函数initFirebase(){
函数carregaDocumentos(){
DocumentsRef.on('value',函数(数据){
headertb=isAdmin?“包括在内的职业道德编辑例外”:“包括在内的职业道德可视化”;
$('#tableCustom thead tr').html(headertb);
$(“#tableCustom”).dataTable().fndroduction();
$('#tableCustom tbody').html('');
for(data.val()中的var键){
documento=data.val()[key]
如果(isAdmin){
linha=“”+
“”+documento.titulo+“”+
“”+documento.data\u inicio+“”+
“”+documento.categoria+“”+
""+
"";
$(“#tableCustom tbody”).append(linha);
}
否则{
linha=“”+
“”+documento.titulo+“”+
“”+documento.data\u inicio+“”+
“”+documento.categoria+“”+
""+
"";
$(“#tableCustom tbody”).append(linha);
嵌入(documento.arquivo,“.modal content”);
}
}
closeLoader();
变量表=$('#tableCustom')。数据表({
“aaSorting”:[[0,“asc”]],
“语言”:{
“sUrl”:“/datatable\u pt.txt”
},
“aoColumnDefs”:[
{“bSortable”:true,“ataargets”:[0]},
{“bSearchable”:true,“aTargets”:[0,1,2]}
]
});
$(“#选择类别”)。每个(功能(i){
变量选择=$(“”)
.appendTo($(this).empty())
.on('change',function(){
表.第列([2])
.search($(this.val())
.draw();
} );
table.column([2]).data().unique().sort().each(函数(d,j){
选择。追加(“”+d+“”)
} );
} );
});
}
卡雷戈斯();
}
HTML:


文件

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

单击“查看”按钮时,应使用嵌入文档填充模态,而不是在加载时填充模态。这可以通过将
documento.arquivo
作为数据属性添加到相应行的模式切换按钮来实现

    <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>