1,这个js只取第一个数组值
2、我使用foreach应该取所有的值
3,我很困惑请帮助
<script>
var unit_balance =
@foreach ($bike as $value)
[{{ $value->unit_balance }}];
@endforeach
function myFunction(){
var totalLessThan20 = unit_balance.filter(unit => unit <= 20);
if(totalLessThan20.length) {
alert("Some of unit left is less than 20. Please restock immediately!");
}
}
</script>
如果你只想要unit_balance
数组中的值,那么使用这个
<script>
var unit_balance = {{json_encode($bike->pluck("unit_balance"))}}
</script>
或者如果你想要整个数组就像在 js 中一样,那么pluck
从上面的代码中删除,像这样
<script>
var unit_balance = {{json_encode($bike)}}
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句