javascript 在Laravel gradebook软件中实现按钮时出现的问题

3lxsmp7m  于 2023-05-27  发布在  Java
关注(0)|答案(1)|浏览(94)

我正在用Laravel做一个管理学生笔记的项目。我有一个students.blade.php文件,其中的等级反映如下:

@foreach ($indicators as $indicator)
 <td class="center">
{{ number_format($notes[ $indicator->id ] ?? 0, 2) }}
 </td>
@endforeach

我有一个功能,允许我通过这样的输入手动更改注解:

<a href="{{ route('web.notes.students-indicators', [$entity->id, $student->id]) }}" data-title="Student Notes: {{ $student-> full_name }}" data-reload="1" class="swal-ajax green-text tooltipped" data-position="top" data-tooltip="Student Notes: {{ $student->full_name }}" ><i class="fa fa-book-reader"></i></a>

这段代码连接到一个名为fields.blade.php的文件,并允许您通过如下输入修改注解:

<input type="hidden" name="notes[{{ $loop->index }}][indicator_id]" value="{{ $indicator->id }}">
<input type="number" class="input_note" name="notes[{{ $loop->index }}][note]" step="0.01" value="{{ $notes[ $indicator->id ] ??0 }}" min="0" max="100">

我想知道的是如何通过传递默认成绩的按钮来更改学生的成绩,例如:3.5并分配该等级,而不是手动输入,我很感激,如果你能带领我的解决方案
我尝试使用一个 AJAX 函数,允许抓取按钮分配的值并将其发送到后端,但它不起作用

j2cgzkjk

j2cgzkjk1#

students.blade.php

@foreach ($indicators as $indicator)
<td class="center">
   {{ number_format($notes[$indicator->id] ?? 0, 2) }}
     </td>
@endforeach

<td class="center">
{{ number_format($notes->avg(), 2) }}
   </td>

<td class="center">
{{ getScaleValoration($valorationScale, $notes->avg()) }}
   </td>
<td style="width: 300px;">
<a href="{{ route('web.notes.students-indicators', [$entity->id, $student>id]) }}"
 data-title="Notas Estudiante: {{ $student->full_name }}" data-reload="1" 
   class="swal-ajax green-text tooltipped" data-position="top" data- 
      tooltip="Notas Estudiante: {{ $student->full_name }}"><i class="fa 
        fa-book-reader"></i></a>
</td>

fields.blade.php:

@foreach ($indicators as $indicator)
 <tr>
 <td>{{ $indicator->name }}</td>
 <td class="center">
 <input type="hidden" name="notes[{{ $loop->index 
}}][indicator_id]" value="{{ $indicator->id }}">
<input type="number" class="input_note" name="notes[{{ $loop->index }}][note]" step="0.01" value="{{ $notes[ 
$indicator->id ] ?? 0 }}" min="0" max="100">
</td>
</tr>
@endforeach

<script>
$('#total_note').on('keyup', __changeNote__);
function __changeNote__(e) {
    _v = $(this).val();
    $('.input_note').val(_v)
}
</script>

edit.blade.php:

<form method="POST" action="{{ route('web.notes.students-indicators- 
update', [$entity->id, $student->id]) }}" class="row" autocomplete="off" 
onsubmit="return false;">
@include('pages.notes.partials.fields')
</form>

路线:

Route::post('/{id}/lista/{student_id}',
        [
            'as' => 'web.notes.students-indicators',
            'uses' => 'Web\\Notes\\MainController@get_indicators'
        ])->middleware('permission:notes.show');

post_indicators函数:

public function post_indicators( Request $request, $id,$student_id )
{
    try {
        $entity = AcademicLoad::where('teacher_id', Auth::user()->id)->findOrFail($id); $student = $entity->course->students()->where('students.id', $student_id )->first(); foreach ($request->input('notes', []) as $data)
        {
            $data['student_id'] = $student->id;
            $data['course_id'] = $entity->course->id;
            $data['period_id'] = current_period()->id;

            $n = [ 'note' => $data['note'] ];
            unset($data['note']);
            $note = Entity::updateOrCreate($data, $n) ;
        }
        return [ 'title' => null, 'message' => null, 'status' => 'success' ];
    } catch(\Exception $e) {
        return [ 'title' => 'Error', 'message' => $e->getMessage(), 'status' => 'error' ];
    }
}

相关问题