doudao1922 2019-06-07 09:12
浏览 45

动态加载对象数组以在模态中查看它们

A php function loops through an array of objects and lists down their titles. I have a link that opens a modal. How can I dynamically load the modal header and body with regard to the object $r from the $results when I press details.

<?php
foreach ($results as $r) {
?>
<div class="row justify-content-center">
    <div class="alert alert-success">
        <strong>
            <?php echo $r['_source']['title']; ?></strong> <span id="showSearchTerm"></span></br>
        <a data-target="#myModal" data-toggle="modal" class="MainNavText" id="MainNavHelp" href="#myModal">Details</a>
    </div>
</div>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <!-- <button type="button" class="close" data-dismiss="modal">&times;</button> -->
                <h2 class="modal-title">
                    <?php echo $r['_source']['title']; ?>
                </h2>
            </div>
            <div class="modal-body">
                <p>
                    <?php echo $r['_source']['body']; ?>
                </p>
                <p>
                    <?php echo $r['_source']['path']['real']; ?>
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<?php

}
  • 写回答

1条回答 默认 最新

  • dso0139 2019-06-07 13:06
    关注

    Take the information you need to fill up the modal from an ajax call. After that you can add that content with:

    $(".classname").append(information_from_ajax_call_stored_in_variable);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析