【发布时间】:2021-05-16 21:08:19
【问题描述】:
我有一个动态刀片,我将值放入三个文本字段并将该值存储在数组中。
我的刀是这样的
在我的 Laravel Livewire 控制器中,我有以下代码
public $veriProducts = [];
public function render()
{
$products = Product::where('user_id', auth()->user()->id)
->orderBy( $this->sortBy, $this->sortAsc ? 'ASC' : 'DESC');
$products = $products->paginate($this->perPage);
info($this->veriProducts);
return view('livewire.products', [
'items' => $products,
]);
}
public function addProduct()
{
$this->veriProducts[] = ['price' => '', 'quantity' => ''];
}
public function removeProduct($index)
{
unset($this->veriProducts[$index]);
$this->veriProducts = array_values($this->veriProducts);
}
这是我的刀
<tbody>
@foreach ($veriProducts as $index => $orderProduct)
<tr>
<td>
<input type="number" name="veriProducts[{{$index}}][price]" class="border border-gray-300 form-control my-0 p-1 ring-blue-200 rounded-md" wire:model="veriProducts.{{$index}}.price" />
</td>
<td>
<input type="number" name="veriProducts[{{$index}}][quantity]" class="border border-gray-300 form-control my-0 p-1 ring-blue-200 rounded-md" wire:model="veriProducts.{{$index}}.quantity" />
</td>
<input type="number" name="veriProducts[{{$index}}][total]" class="border border-gray-300 form-control my-0 p-1 ring-blue-200 rounded-md" wire:model="veriProducts.{{$index}}.total" />
</td>
<input type="number" name="veriProducts[{{$index}}][pl]" class="border border-gray-300 form-control my-0 p-1 ring-blue-200 rounded-md" wire:model="veriProducts.{{$index}}.pl" />
</td>
</tr>
@endforeach
它工作正常我可以添加行,并且数组 $veriProducts 也可以正常创建。 数量文本框松散焦点或其他内容后如何计算总和盈亏
Total will be
price*quanrity
PL will be
20% less then total
非常感谢
【问题讨论】: