dongyupen6269 2018-08-10 13:42
浏览 62
已采纳

单击表行返回不正确的数据

Thanks for taking your time looking at my problem.

I have a view returning data from my database passing it through the controller:

public function index()
    {
        $members = Member::orderBy('id', 'desc')->paginate(5);

        return view('home', compact('members'));
    }

I'm happy with the view: enter image description here

I'm passing it to the view with a foreach loop:

 @foreach ($members as $member)

 @include('partials.tableRow')

 @endforeach

My tableRow looks like this:

<a class="panel-block" onclick="refs.show.open()">
  <span class="panel-icon">
    <i class="fas fa-user" aria-hidden="true"></i>
  </span>
  <span class="column is-4">
    {{ $member->name }}
  </span>
  <span class="panel-icon">
    <i class="fas fa-at" aria-hidden="true"></i>
  </span>
  <span class="column is-5">
    {{ $member->email }}
  </span>
  <span class="panel-icon">
    <i class="fas fa-tshirt" aria-hidden="true"></i>
  </span>
  <span class="panel-button column is-1">
    {{ $member->size }}
  </span>
  <span class="panel-icon">
    <i class="fas fa-coins" aria-hidden="true"></i>
  </span>
  <span class="panel-button column is-2">
    {{ $member->points}}
  </span>
</a>

The problem comes when i click on the individual table row. I want it to display the data connected to the information at the individual table row. On the picture below I've clicked the first row (my own name) and up comes this: wrong data display

As you may see it's showing the info from the last row and does it every time i click a row. Same problem when I go further down the pagination.

I've checked to see if I get the data passed to the view and i do: data passed to view

My showMember modal looks like this:

<div class="modal" id="show">
  <div class="modal-background" onclick="refs.show.close()"></div>
  <div class="modal-card">
    <header class="modal-card-head">
      <p class="modal-card-title">{{ $member->name }}</p>
      <button class="delete" onclick="refs.show.close()" aria-label="close"></button>
    </header>
      <section class="modal-card-body">

        <!-- Content -->
        <li class="panel-block">
          <label class="column is-2"><b>E-mail</b></label>{{ $member->email }}
        </li>

        <li class="panel-block">
          <label class="column is-2"><b>T-shirt</b></label>{{ $member->size }}
        </li>

        <li class="panel-block">
          <label class="column is-2"><b>Points</b></label>{{ $member->points }}
        </li>
        <!-- Content -->

      </section>
      <footer class="modal-card-foot">
        <button class="button is-outline" onclick="refs.show.close()">Luk</button>
      </footer>

  </div>
</div>

I might be missing some link to an id or something in order to pass the specific data to the modal or is the problem with the javascript function not getting the passed data besides the last?

Thank you in advance

  • 写回答

2条回答 默认 最新

  • dongpao5261 2018-08-10 13:54
    关注

    Cannot tell exactly for laravel, however in (Yii2, Symfony) returned view is executed and kind of died. You can change content of your modal dynamically only with javascript, which will load data by AJAX or get from hidden element and load to the modal.

    Show your refs.show.open(), please.

    Update from 13 Aug 2018

    So you can do something like this before showing modal.

    document.getElementById('modal-email').innerText = this.getElementsByClassName('member-email').item(0).innerText;
    document.getElementById('modal-size').innerText = this.getElementsByClassName('member-size').item(0).innerText;
    document.getElementById('modal-points').innerText = this.getElementsByClassName('member-points').item(0).innerText;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示