【问题标题】:Getting chat id by row on click单击时按行获取聊天ID
【发布时间】:2017-07-19 08:52:26
【问题描述】:

我有一个填满数据的表格。我已经显示了它,但是现在当我单击每一行上的历史按钮时,获取该行的 chat_id 并将其传递给控制器​​。到目前为止,我正在传递一个 ID 数组,但我无法让它工作。

以下是我目前的代码:

//观看次数

<?php $arr = 0; ?>
    @foreach($chat as $row)
        <tr>
            <td>{{ $row->chat_id }}</td>
            <td>{{ $row->fullname }}</td>
            <td>{{ $row->email }}</td>
            <td>{{ $row->plaintext }}</td>
            <td>{{ $row->transcript_text }}</td>
            <td>{{ $row->duration }}</td>
            <td>
                <button type="submit" name="history" onclick="javascript:getID('{{$row->chat_id}}','{{$arr}}')">History</button>
                <input name="recordid[]" id="recordid[]" type="hidden">
            </td>
        </tr>
        <?php $arr++; ?>
    @endforeach
    <script type="text/javascript">
        function getID(id, arr){
            $('[id^=recordid]').eq(arr).val(id);
        }
    </script> 

//控制器

public function showMessage(){
    $id = Input::get('recordid');
    $history = Chat::where('chat_id','=', $id)->get();
    return View::make('chat.chatview')->with(array('history'=>$history));
}

【问题讨论】:

    标签: javascript php jquery html laravel-4


    【解决方案1】:

    您提供给模板的数组名称是历史记录with(array('history'=&gt;$history));,而不是聊天@foreach($chat as $row) 循环历史记录@foreach($history as $chat) 以获得结果

    【讨论】:

    • @foreach($chat as $row) 是我显示的数据,这里我有提交按钮历史记录,它应该让我使用该特定行的 chat_id 进入另一个模板。这是另一个模板:

      聊天历史

      @foreach($history as $row)
      {{$row->transcipt_text}}
      @endforeach
    • 请告诉我你的代码中的 $chat 数组在哪里?它在哪里定义?您循环遍历模板或代码中未定义的数组
    • 我正在获取路由中的聊天模型 Route::get('individual', function(){ $chat = Chat::all(); return View::make('chat/individual ')->with('chat', $chat);});
    • 也许 View::make('chat/individual')->with(array('chat' => $chat);}) ???
    猜你喜欢
    • 2019-10-09
    • 1970-01-01
    • 2020-04-14
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多