【问题标题】:Laravel Livewire, how to send the value of an option tag to wire:model=" category"?Laravel Livewire,如何将选项标签的值发送到wire:model =“ category”?
【发布时间】:2021-05-12 13:44:15
【问题描述】:

我在 cart.blade 文件中有一个 select 元素,如下所示:

<select wire:model="category">
   @foreach ($categories as $item)
      <option value="{{$item->id}}">{{$item->name}}</option>
   @endforeach
</select>

当我从列表中选择一个项目时,它不会将选项标签的值发送到组件中的类别变量(只是发送从1到n的已选选项的排序数)。

如何将选项标签的值发送到wire:model="category"?

【问题讨论】:

  • 尝试把 name="category" 放在选择中
  • 以及如何将其与组件中的category var同步,如wire:model="category"?
  • 尝试检查dom,看看value属性是否设置为只有id,并检查category变量,它不能是数组。

标签: php laravel laravel-livewire


【解决方案1】:

您介意尝试以下方法吗?

class GroupMoney extends Component
{
    public $category_id;
    public $category;

    public function updatedcategory($value)
    {
        if (!empty($value)) {
            $this->category_id = category::find($value);
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2015-03-22
    • 2012-11-01
    相关资源
    最近更新 更多