Laravel 中的动态 Bootstrap 模态

问题描述

我想在 Bootstrap Modal 中动态显示产品详细信息。 这是我的控制器

$products = Product::all();
return view('landing')->with('products',$products);

我的观点

@foreach($products as $index => $product)
 <div class="product-text col-lg-6">
  <h3><a href="#">{{$product->name}}</a></h3>
   <div class="product-Meta">
    <p>{{$product->details}}</p>
   </div>
   <a data-toggle="modal" data-target="{{ $index }}">Modal</a>
  </div>
@endforeach
      
    <div class="modal fade" id="{{ $index }}" role="dialog">
        <div class="modal-dialog modal-dialog-centered modal-lg">
        
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
            <h4 class="modal-title">{{$product->name}}</h4>
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            
            </div>
            <div class="modal-body">
            <p>{{$product->description}}</p>
            </div>
            <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
        
        </div>
    </div>

如何显示特定产品的详细信息?

解决方法

我们可以使用两种方法来解决这个问题。

  1. 使用 text = 'Overview At Emburse our mission is to help make our users’ lives — and their businesses – better.We are dramatically transforming how organizations manage corporate expenses and invoices. We humanize work by automating manual tasks and saving users’ time,so they can focus on what matters most — their family,community,or more rewarding work.We help CFO’s give their employees a simple and amazing experience while ensuring.compliance and reducing costs. Our solutions are tailored for companies from start-ups to enterprises. We have more than 14,000 clients and 4.5 million users globally. Embue ' print(len(text)) parser = GingerIt() result=parser.parse(text) print(result) 包含模型代码。 实际上,这不是一个好方法。加载页面需要更多时间,这不是一个好习惯

  2. 使用 foreach。这是通过单击按钮在模型上显示您的产品详细信息的最佳方式

所以你可以使用第二种方式。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...