我尝试将 id 值传递给我的另一个 Blade ,它起作用了,但另一个 Blade 文件在第一个数字处没有读取 0 的数字。例如,当我传递值 006 时,当我从另一个 Blade View 控制台记录该值时,它只显示 6。
我的 onclick 值已传递
<a class="btn btn-sm btn-default pull-right" type="button" title="Search Branch" onclick="openNewWindow('{{ route('reporting.branchCheckBoxList', ['cuid' => '_cuid_', 'stid' => '_stid_']) }}'.replace('_cuid_', document.getElementById('cu').value).replace('_stid_', document.getElementById('state').value))" ><i class="fa fa-hand-o-up">
网络路由
Route::get('reporting/branchCheckBoxList/{cuid}/{stid?}','GenReportController@branchCheckBoxList')->name('reporting.branchCheckBoxList');
我的 Controller
public function branchCheckBoxList($cuid, $stid ) {
$cuid = $cuid;
$stid = $stid;
return view('report.BranchCheckBoxList', compact('cuid','stid'));
}
我的其他 Blade View
<script>
var cuid = {{ $cuid }} ;
console.log(cuid); //my console only read 6 if i pass 006
</script>
我需要修复我的值,该值可以在第一个数字处返回读取数字0,抱歉我的英语不好
最佳答案
您的代码没有显示前导零,当您使用 laravel dd 函数时,输出为 006 但 console.log 函数会删除前导零。
如果您希望显示前导零,则必须将其格式化为字符串。
<script>
var cuid = "{{$cuid}}";
console.log(cuid);
</script>
关于javascript - 我的 id 值在传递到其他 Blade 后未从第一个数字读取数字 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60070540/