php - 带有 Livewire 的 Laravel 待办事项列表
问题描述
我需要一些帮助。我最近开始了一个测试项目,用 Laravel Livewire 制作一个基本的待办事项列表。一切都很好,但最后我有编辑功能我在删除未定义偏移量的 Todo 中的步骤时遇到错误:0 突出显示此特定代码行:$step=$this->steps[$index];。下面是代码
public function remove($index)
{
$step=$this->steps[$index];
if(isset($step['id']))
{
Step::find($step['id'])->delete();
}
unset($this->steps[$index]);
}
$index 值由edit-step.blade.php 文件传递,如下所示:
@foreach ($steps as $step)
<div class="form-group row" wire:key={{ $loop->index }}>
<div class="col-lg-11">
<input type="text" class="form-control" placeholder="Describe Step {{ $loop->index+1 }}" style="margin-bottom:2px;" name="stepName[]" value="{{ $step['name'] }}"/>
<input type="hidden" name="stepId[]" value="{{ $step['id'] }}"/>
</div>
<span class="fa fa-times col-md text-md-left" style="color:red; cursor: pointer; margin-top:10px;" wire:click="remove({{ $loop->index }})"></span>
</div>
你能帮我解决我哪里出错了。
解决方案
对不起,我还不能评论!您正在传递$loop->index
给remove
函数而不是$step['id']
.
推荐阅读
- kivy - 是否可以在 kivy 应用程序中显示谷歌日历?
- vb.net - Visual Studio Enterprise 2019 中的连续字符导致 BC30201 错误
- character-encoding - iPython REPL 收到来自文本编辑器的错误字符 (Windows 10)
- excel - Excel 函数用于查看单元格中的文本
- javascript - 添加 Stripe 卡后重置 StripeCardComponent
- python - Flask WTforms 中的 CSS 适用于按钮,但不适用于其他按钮
- angular - 我的 Angular HTTPClient POST 请求这个简单的 URL 发布请求吗
- android - google play计费库订阅中的交易ID和原始交易ID
- node.js - paginate 不是 adonis / node.js 中的函数
- python - 在 Python 中将未知变量设置为未知值