dtgj8529 2019-06-04 12:54
浏览 38

如何从查询的弹性搜索结果中动态加载数据到模态?

I have an index in elasticsearch and I can query it, resulting in an array of objects. I am able to list all the titles from the array. Now I would like to loop through the result so that when I press the details button, a modal with more details on that document opens. Is there any way to do this?

<?php
    if (isset($results)) {
        foreach ($results as $r) {
        ?>
        <div class="row justify-content-center">
            <div class="alert alert-success">
            <strong><?php echo $r['_source']['title']; ?></strong> || Date: <?php echo $r['_source']['date']; ?> <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

          }
        }
        ?>
    </div>
    <!--end of col-->
</div>
</div>

<script>
$('a[href$="#Modal"]').on( "click", function() {
   $('#Modal').modal('show');
});
</script>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line