blade 中 Laravel 8 的奇怪输入渲染问题
Strange input rendering issue in blade for Laravel 8
我在 blade 中有以下代码:
@if ($selectedChapter ?? '')
<input type="hidden" id="selectedChapter" name="selectedChapter" value="{{$selectedChapter->id}}">
@endif
@if ($question ?? '')
<input type="hidden" id="questionId" name="questionId" value="{{$question->id}}">
@endif
<input type="hidden" id="answer_id" name="answer_id" value="@if(isset($answer_id)){{$answer_id}}@endif">
<input type="hidden" id="wrong" name="wrong" value="@if(isset($wrong)){{$wrong}}@endif">
<input type="hidden" id="first" name="first" value="{{$first ?? ''}}">
<input type="hidden" id="firstQuestion" name="firstQuestion" value="{{$firstQuestion ?? ''}}">
<input type="hidden" id="lastQuestion" name="lastQuestion" value="{{$lastQuestion ?? ''}}">
由于某种原因,字段未正确呈现。发生的情况是其他所有字段都在渲染。 selectedChapter answer_id、first 和 lastQuestion 字段正在呈现。
如果我更改字段的顺序,会发生同样的事情,但顺序不同。知道为什么会这样吗?
我认为您不需要对每个值都进行验证,太多 isset
并且不需要 ??
。
在 blade 视图中,当您需要为输入设置一个值时,您从源中检索该值,blade 会自动验证该值是否为 null 或空,否则,它不会显示任何内容。
这应该有效:
@if($selectedChapter)
<input type="hidden" id="selectedChapter" name="selectedChapter" value="{{$selectedChapter->id}}">
@endif
@if($question)
<input type="hidden" id="questionId" name="questionId" value="{{$question->id}}">
@endif
<input type="hidden" id="answer_id" name="answer_id" value="{{ $answer_id }}">
<input type="hidden" id="wrong" name="wrong" value="{{ $wrong }}">
<input type="hidden" id="first" name="first" value="{{ $first }}">
<input type="hidden" id="firstQuestion" name="firstQuestion" value="{{ $firstQuestion }}">
<input type="hidden" id="lastQuestion" name="lastQuestion" value="{{ $lastQuestion }}">
当然...问题是 iCheck jquery 插件,更具体地说是 selector。我昨天做了一些修改,把selector从input.line改成了input。结果是 select 更多的输入字段。不管怎样,现在已经修复了。
我在 blade 中有以下代码:
@if ($selectedChapter ?? '')
<input type="hidden" id="selectedChapter" name="selectedChapter" value="{{$selectedChapter->id}}">
@endif
@if ($question ?? '')
<input type="hidden" id="questionId" name="questionId" value="{{$question->id}}">
@endif
<input type="hidden" id="answer_id" name="answer_id" value="@if(isset($answer_id)){{$answer_id}}@endif">
<input type="hidden" id="wrong" name="wrong" value="@if(isset($wrong)){{$wrong}}@endif">
<input type="hidden" id="first" name="first" value="{{$first ?? ''}}">
<input type="hidden" id="firstQuestion" name="firstQuestion" value="{{$firstQuestion ?? ''}}">
<input type="hidden" id="lastQuestion" name="lastQuestion" value="{{$lastQuestion ?? ''}}">
由于某种原因,字段未正确呈现。发生的情况是其他所有字段都在渲染。 selectedChapter answer_id、first 和 lastQuestion 字段正在呈现。
如果我更改字段的顺序,会发生同样的事情,但顺序不同。知道为什么会这样吗?
我认为您不需要对每个值都进行验证,太多 isset
并且不需要 ??
。
在 blade 视图中,当您需要为输入设置一个值时,您从源中检索该值,blade 会自动验证该值是否为 null 或空,否则,它不会显示任何内容。
这应该有效:
@if($selectedChapter)
<input type="hidden" id="selectedChapter" name="selectedChapter" value="{{$selectedChapter->id}}">
@endif
@if($question)
<input type="hidden" id="questionId" name="questionId" value="{{$question->id}}">
@endif
<input type="hidden" id="answer_id" name="answer_id" value="{{ $answer_id }}">
<input type="hidden" id="wrong" name="wrong" value="{{ $wrong }}">
<input type="hidden" id="first" name="first" value="{{ $first }}">
<input type="hidden" id="firstQuestion" name="firstQuestion" value="{{ $firstQuestion }}">
<input type="hidden" id="lastQuestion" name="lastQuestion" value="{{ $lastQuestion }}">
当然...问题是 iCheck jquery 插件,更具体地说是 selector。我昨天做了一些修改,把selector从input.line改成了input。结果是 select 更多的输入字段。不管怎样,现在已经修复了。