微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Laravel 8 刀片中的奇怪输入渲染问题

如何解决Laravel 8 刀片中的奇怪输入渲染问题

我在刀片中有以下代码

                @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。结果是选择了更多的输入字段。无论如何现在它固定了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。