使用单击功能显示刀片模型中的数据

时间:2017-10-27 12:49:44

标签: php jquery mysql laravel-5.4

我正在使用按钮显示特定人员的详细信息,使用data-toggle =" modal"但按钮没有执行任何操作。当我单击按钮时,我无法显示用户的任何详细信息。

路线:

public function show()
    {
        $patient_user=patient_user::all();
        return view('document')->with('patient_user',$patient_user);
    }

控制器:

<form id="myForm" method="get">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="panel-body">
            <table class="table table-striped table-bordered table-hover table-full-width" id="sample_1">
                <thead>
                    <tr>
                        <th>Patient ID</th>
                        <th>Patient Name</th>
                        <th>Full Name</th>
                        <th>DOB</th>
                        <th>Ref. Name</th>
                        <th>Payment</th>
                        <th>Doc Status</th>
                        <th>Appointment</th>
                        <th>Action</th>
                    </tr>
                </thead>
                @foreach($patient_user as $key=>$row)
                <tbody>
                    <tr>
                        <td>{{$row->patient_id}}</td>
                        <td>{{$row->patient_firstname}}</td>
                        <td>{{$row->patient_firstname}} {{$row->patient_lastname}}</td>
                        <td>{{$row->dob}}</td>
                        <td>{{$row->refering_physician_name}}</td>
                        <td>{{$row->dob}} </td>
                        <td>{{$row->dob}}</td>
                        <td>{{$row->app_date}}</td>
                        <td class="center">
                            <div class="visible-md visible-lg hidden-sm hidden-xs">
                                <a href='{{ url("Trail/{$row->patient_id}") }}' class="btn btn-xs btn-teal tooltips" data-placement="top" data-original-title="Edit"><i class="fa fa-edit"></i></a>
                                <a href='#' data-toggle="modal" class="btn btn-xs btn-green tooltips" data-id="{{ $row->patient_id}}" data-target="static" onclick="pat_det{{ $row->patient_id }}" data-placement="top" data-original-title="View" id="pat_det"><i class="fa fa-eye"></i></a>
                                <a href='{{ url("destroy/{$row->patient_id}") }}' class="btn btn-xs btn-bricky tooltips" data-placement="top" data-original-title="Remove"><i class="fa fa-times fa fa-white"></i></a>
                            </div>
                        </td>
                    </tr>
                </tbody>
                @endforeach
            </table>
        </div>
        <div id="static" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false" style="display: none;">
            <div class="modal-body">
                <h4><i>Patient Details</i></h4> 
            </div>
            <div class="modal-body">
                <div class="col-md-12">
                    <div class="col-md-6">First Name</div>
                    <div class="col-md-5" id="fname"> {{ $row->patient_firstname}} </div>
                </div>
                <br>
                <div class="col-md-12">
                    <div class="col-md-6">Middle Name</div>
                    <div class="col-md-5" id="mname"> {{ $row->middle_name}} </div>
                </div>
                 <br>
                 <div class="col-md-12">
                    <div class="col-md-6">Last Name</div>
                    <div class="col-md-5" id="lname"> {{ $row->patient_lastname}} </div>
                 </div>
            </div>
        </div>
</form>

查看:

<script type="text/javascript">
    $('#static').on('show', function(e) 
    {
                e.preventDefault();
                var link     = e.relatedTarget(),
                modal    = $(this),
                patient_firstname = link.data("patient_firstname"),
                middle_name = link.data(middle_name),
                patient_lastname = link.data("patient_lastname"),

                modal.find("#fname").val(patient_firstname);
                modal.find("#mname").val(middle_name);
                modal.find("#lname").val(patient_lastname);

    });
</script>

jquery的:

#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <unistd.h>
#include <iostream>
#include <pthread.h>

int f(int x) {
    if (x == 0) return 1;
    return x % 100;
}

void *deal(void *arg) {
    int fd = * (int *) arg;
    int x;
    int n = read(fd, &x, sizeof x);
    if (n < 0) std::cout << "error reading"  << std::endl;
    std::cout << "request " << x << " received" << std::endl;
    int y = f(x);
    write(fd, &y, sizeof y);
    std::cout << "response to " << x << ": " << y << std::endl;
    close(fd);
    return NULL;
}

int main(int argc, char *argv[]) {
    int port = atoi(argv[1]);
    int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
    sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_port = htons(port);
    bind(socket_fd, (sockaddr *) &addr, sizeof addr);
    listen(socket_fd, 20);
    std::cout << "listen on " << port << std::endl;
    sockaddr remote_addr;
    socklen_t len;
    for (; ;) {
        int fd = accept(socket_fd, &remote_addr, &len);
        pthread_t p;
        pthread_create(&p, NULL, deal, (void *) &fd);
    }
    return 0;
}

其中#static是我的模态ID,find中的值是特定字段的id,而val是数据库值。

1 个答案:

答案 0 :(得分:0)

问题在于您从未设置的属性请求数据。

patient_firstname = link.data("patient_firstname"),

以上部分正在尝试检索属性data-patient_firstname的值。由于原始链接没有此属性,因此不会有任何数据。

更改

<a href='#' data-toggle="modal" class="btn btn-xs btn-green tooltips" data-id="{{ $row->patient_id}}" data-target="static" onclick="pat_det{{ $row->patient_id }}" data-placement="top" data-original-title="View" id="pat_det"><i class="fa fa-eye"></i></a>

<a href='#' data-toggle="modal" 
data-patient_firstname="{{$row->patient_firstname}}" <-- do this for all requested vars
class="btn btn-xs btn-green tooltips" data-id="{{ $row->patient_id}}" data-target="static" onclick="pat_det{{ $row->patient_id }}" data-placement="top" data-original-title="View" id="pat_det"><i class="fa fa-eye"></i></a>

这样data-*属性就可以使用了。