laravel - 我无法使用 Laravel-Livewire 在模态中显示数据
问题描述
我尝试使用 dd() 并且可以看到数据,但是当我尝试从刀片验证 maxPoints 变量中是否有任何值时,我得到空值,与变量名相同。
<?php
namespace App\Http\Livewire;
use App\Tests as Test;
use Livewire\Component;
class Tests extends Component
{
public $selected_id, $name, $maxPoints, $counter;
public function render()
{
return view('livewire.tests.index', ['tests' => Test::get()]);
}
public function edit($id){
$test = Test::findOrFail($id);
$this->selected_id = $id;
$this->name = $test->name;
$this->maxPoints = $test->maxPoints;
// dd($this->name);
}
}
在模态中,我尝试显示数据但我没有得到值,它显示为空。
<div wire:ignore.self class="modal fade" id="editTest" data-backdrop="static" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Update</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span wire:click.prevent="cancel()" aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<input type="hidden" wire:model="selected_id">
<div class="form-group">
<label for="name"></label>
<input wire:model="name" type="text" class="form-control" id="name"
placeholder="Name">
</div>
<div class="form-group">
<label for="email"></label>
@if ($maxPoints)
<input wire:model="maxPoints" value="{{ $maxPoints }}" type="text" class="form-control"
id="email" placeholder="Email">
@endif
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" wire:click.prevent="cancel()" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<button type="button" wire:click.prevent="update()" class="btn btn-primary"
data-dismiss="modal">Save</button>
</div>
</div>
</div>
</div>
解决方案
推荐阅读
- javascript - Chrome 中的缓存失效
- c# - 为什么选择并发字典
.tryAdd 修改字典中项目的顺序 ? C# - php - PHP __destruct 公共变量
- angular - 在甜甜圈图中调用 fontSize 函数(打字稿)
- php - 如果保存在 id laravel 中,如何在下拉列表中选择多个项目?
- python - 用mechanicalsoup下载文件
- c - “在C程序中,如何取一个(char数组),即用户输入的字符串(包括空格),其长度也应该是用户输入的值?
- haskell - 试图用 SBV 解决祖先关系的约束
- angular - 为什么我在传单弹出窗口中的按钮不起作用?
- c# - 如何将 XAML 文件中 LayoutAnchorableItem 的 Style 属性与 AvalonDock 绑定?