问题描述
我在刀片中有以下代码:
@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
和 ??
不是必需的。
在刀片视图中,当您需要为输入设置值时,您可以从源中检索该值,刀片会自动验证该值是否为 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 插件,更具体地说是一个选择器。我昨天做了一些修改,将选择器从 input.line 更改为 input。结果是选择了更多的输入字段。无论如何现在它固定了。