如果我在控制器中<div class="well" id ="mainWell">
<div class="draggable">CONTENT</div>
<div class="draggable">CONTENT 2</div>
<div class="draggable">CONTENT 3</div>
</div>
<div id="droppable1" class="well col-md-3" style="z-index:-1;"></div>
<div id="droppable2" class="well col-md-9" style="z-index:-1;"></div>
<script>
$('.draggable').draggable({
helper: 'clone',
revert: "invalid",
containment: "document"
});
$(document).on('click','.draggable',function(){
$(this).appendTo('#mainWell');
$(this).draggable({
helper: 'clone',
revert: "invalid",
containment: "document"
});
});
//ui.draggable is the object of dragged item
$('#droppable1, #droppable2').droppable({
accept: '.draggable',
drop: function (event, ui) {
ui.draggable.remove();
$(this)
.append(ui.helper.addClass('test').clone(false).css({
position: 'relative',
left: '0px',
top: '0px',
color:'red'
})
);
}
});
</script>
,则结果如下:
在视图刀片laravel中,我检查收集是否为空:
dd($items);
但这不起作用
我该如何解决这个问题?
答案 0 :(得分:8)
您可以使用$ items-> isEmpty();或$ items-> isNotEmpty();
像这样:
@if(!$items->isNotEmpty())
...
@endif
您可以在这里进一步阅读: https://laravel.com/docs/5.5/collections#method-isempty
答案 1 :(得分:0)
@if ( $items->count() )
....
@endif
答案 2 :(得分:0)
我通常会仔细检查,以便如果我没有得到该值,页面将继续运行:
@if(isset($items))
@if(!empty($items))
.....
@endif
@endif
希望对您有帮助