【问题标题】:Laravel 5 View need to be get functioned properlyLaravel 5 View 需要正常运行
【发布时间】:2017-11-12 22:50:30
【问题描述】:

我是 laravel 5.4 的新手,所以我需要解决这个问题。

我正在为我的公司开发考勤管理系统。为了过滤学员,我开发了这样的搜索控制器功能。

 public function search_code(Request $request){
    $query = $request->search;
    $queryType = $request->institute; // 'id' or 'name'
    $items = DB::table('registerdetails');        

    if($queryType == 'id'){
      $items = $items->where('trainee_id', 'LIKE',"%$query%");
    }
    if($queryType == 'full_name'){
      $items = $items->where('full_name', 'LIKE',"%$query%");
    }
   $items = $items->get();

    return view('traineeattendance.index')->with('items',$items);

            }

这样看它的样子。

如您所见,这将返回搜索功能下的所有值。这是在 index.blade.php 上。

然后在进行搜索后它会被过滤。然后我按右侧的添加考勤按钮。这样添加考勤表的第一个字段需要根据搜索结果自动填写。这意味着 Trainee_Id。请参阅此图片。

所以这是添加考勤表单视图,名为 admission.blade.php。

  <form action="{{route('TraineeAttendance.store')}}" method="post" >
       {{ csrf_field() }} 
       &nbsp;  &nbsp;  &nbsp;

    <div class="form-group">

    <label>Trainee ID</label>
    <input type="text" name="trainee_id" class="form-control" value="MOB/TR/">
    </div>

    <div class="form-group">
    <label>Name </label>
    <input type="text" name="name" class="form-control" value="">
    </div>

    <div class="form-group">
            <label >Starting Time</label>       
            <input class="form-control" type="time" value="" id="example-time-input" name="starting_time">
    </div>

     <div class="form-group">
            <label >End Time</label>        
            <input class="form-control" type="time" value="" id="example-time-input" name="end_time">
    </div>

     <div class="form-group">
            <label >Site Visit Time</label>     
            <input class="form-control" type="time" value="" id="example-time-input" name="site_visit_time">
    </div>

谁能帮我解决这个问题?这对我很有帮助。

【问题讨论】:

  • 你在用jQuery之类的某个js库吗?
  • 没有先生,只有 laravel 和 html
  • 您需要搜索并且对于每个搜索结果都必须添加出勤率?我说的对吗?
  • 可以这样说。我搜索了培训 ID MOB/TR/1741 然后按搜索按钮。它给出过滤值。为此我需要添加出勤率。如上所示,添加出勤表第一个字段需要自动填充
  • 当您为其中一个搜索结果添加考勤时,您需要自动在输入字段中输入 MOB/TR/1741 吗?

标签: php forms laravel laravel-5 view


【解决方案1】:

在 JS 中:

您可以通过在onclick 事件侦听器上使用this 上下文来检索您需要的每个values 的值(例如实习生ID)。

假设您已经像这样设置了html 出席名单

<tbody>
   <tr>
       <td class="trainee-id"> MOB/TR/Sample 1 </td>
       <td> Sample Training 1 </td>
       <td> 2001-12-12 </td>
       <td> 2001-12-13 </td>
       <td><a href="#" class="add-attendance" onclick="getTraineeId(this)"> Add Attendance </a></td>
   </tr>

   <tr>
       <td class="trainee-id"> MOB/TR/Sample 2 </td>
       <td> Sample Training 2 </td>
       <td> 2001-12-14 </td>
       <td> 2001-12-15 </td>
       <td><a href="#" class="add-attendance" onclick="getTraineeId(this)"> Add Attendance </a></td>
   </tr>

</tbody>

那么对于你的 JS,你可以得到这样的值:

<script> 

function getAttendance(oElement) {
    console.log(oElement) // The DOM Element (e.g add-attendance)
    var sValue = oElement.parentElement.parentElement.getElementsByClassName('trainee-id')[0].value; // Sample value you will get = MOB/TR/Sample 1
}

 </script>

然后在上面给出的 [form] 上,尝试在 [Trainee ID] 输入字段中放置一个 [id]:

<label>Trainee ID</label>
    <input type="text" name="trainee_id" class="form-control"  id="input-trainee-id" value="MOB/TR/">
</div>

您可以从中放置您之前获得的值并将其分配到您的 [Trainee ID] 输入字段中

<script> 

function getAttendance(oElement) {
    console.log(oElement) // The DOM Element (e.g add-attendance)
    var sValue = oElement.parentElement.parentElement.getElementsByClassName('trainee-id')[0].value; // Sample value you will get = MOB/TR/Sample 1
}

 document.getElementById('input-trainee-id').value = sValue;

 </script>

您也可以将其应用于您的其他字段(例如名称/开始时间/结束时间)。希望这将指导您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-10
    • 2017-06-10
    • 1970-01-01
    • 2015-08-06
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多