gpt4 book ai didi

php - 如果 div 类为空(使用 laravel foreachloop)

转载 作者:行者123 更新时间:2023-12-01 06:33:13 25 4
gpt4 key购买 nike

这里我有一个教师的 foreach 循环,以及他们的相关关系,即评论。当我循环浏览老师时,如果他们没有关系或没有评论,我想在包含的 div 中打印“无评论”。我现在使用的代码可以工作,但是如果一位老师有评论,其他类(class)将保持空状态,而不是说“没有评论”。在 laravel 或 js 中有没有办法可以做到这一点?这可能是一个简单的解决方案。有人可以帮我吗?

HTML:

 @foreach($teachers as $teacher)
<div class="item{{{ $isFirst ? ' active' : '' }}}">
<div class = "deck">
<div class = "row marg">
<div class="col-md-8">
<div class = "stdnt">
<h1>Teacher Info</h1>
{!! Form::model( $student, ['url' => ['tchUpd', $teacher->id], 'method' => 'post', 'role' => 'form'] ) !!}
<h1>{{ucwords($teacher->name)}}</h1>
<div class = "form-group fga">
{!!Form::label('title', 'NickName:', ['class' => 'control-label lad']) !!}
{!!Form::text('nick', $teacher->nick, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Email:', ['class' => 'control-label lad']) !!}
{!!Form::text('email', $teacher->email, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Position:', ['class' => 'control-label lad']) !!}
{!!Form::text('pack', $teacher->position, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Bio-Short:', ['class' => 'control-label lad']) !!}
{!!Form::text('short', $teacher->short, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Prof/Edu:', ['class' => 'control-label lad']) !!}
{!!Form::text('profedu', $teacher->profedu, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Interests:', ['class' => 'control-label lad']) !!}
{!!Form::text('interest', $teacher->interest, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Pitch:', ['class' => 'control-label lad']) !!}
{!!Form::text('why', $teacher->why, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::submit('Submit', ['class'=> 'btn btn-danger form-control'])!!}
</div>
{!! Form::close() !!}
</div>
</div>
<div class = "col-md-4">
<div class = "teac">
<h1>Teacher Info</h1>
<div id = "user-profile" class = "addyphoto" style = "background-image: url(/assets/image/{{$teacher->photo}})"> </div>
{!! Form::model( $student, ['url' => ['tchUpd', $teacher->id], 'method' => 'post', 'role' => 'form', 'novalidate' => 'novalidate', 'files' => true] ) !!}
<div class = "form-group fga">
{!!Form::label('title', 'Picture:', ['class' => 'control-label lad']) !!}
{!!Form::text('photo', $teacher->photo, ['class'=> 'input-mini ina tch'])!!}
</div>
<div class = "form-group fga">
{!! form::file('newphoto', null) !!}
{!!Form::submit('Submit', ['class'=> 'btn btn-danger form-control'])!!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<div class = "mask flow">
<div class = "row-fluid marg reviewblock">
@foreach($teacher->reviews as $review)
<div class = "ablock">
<h1>{{ucwords($review->title)}}</h1>
<p>{{$review->created_at}}</p>
<p>{{$review->title}}</p>
<p>{!!$review->description!!}</p>
</div>
@endforeach
</div>
</div>
{{--*/ $isFirst = false; /*--}}
</div>

JS

if ( $('.reviewblock').children().length == 0 ) {
$(this).append("<div class = 'empty'><h1>No Reviews</h1></div>");
}

/--------------第二次尝试---------/

if (isEmpty($('.reviewblock'))) {
$('.reviewblock').append("<div class = 'empty'><h1>No Reviews</h1></div>");
}

最佳答案

您的代码只会在类“.reviewBlock”第一次出现时执行此操作。对所有发生的情况都这样做。

$('.reviewblock').each(function(i, obj) {
if (isEmpty(this))) {
$('.reviewblock').append("<div class = 'empty'><h1>No Reviews</h1></div>");
}
});

关于php - 如果 div 类为空(使用 laravel foreachloop),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32887281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com