Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Livewire Laravel-TypeError:无法读取属性';getAttributeName';空的_Php_Laravel_Laravel Livewire - Fatal编程技术网

Php Livewire Laravel-TypeError:无法读取属性';getAttributeName';空的

Php Livewire Laravel-TypeError:无法读取属性';getAttributeName';空的,php,laravel,laravel-livewire,Php,Laravel,Laravel Livewire,我在发送表单后从Ajax中获取数据。有一个侦听器正在为我的组件设置属性 我试图实现的是在提交表单后显示我的结果。 在组件中,模型已经被很好地检索到,但是当我想将其显示给我的组件时,我得到了一个错误 directive_manager.js:26 Uncaught (in promise) TypeError: Cannot read property 'getAttributeNames' of null at _default.value (directive_manager.js:2

我在发送表单后从Ajax中获取数据。有一个侦听器正在为我的组件设置属性

我试图实现的是在提交表单后显示我的结果。 在组件中,模型已经被很好地检索到,但是当我想将其显示给我的组件时,我得到了一个错误

directive_manager.js:26 Uncaught (in promise) TypeError: Cannot read property 'getAttributeNames' of null
    at _default.value (directive_manager.js:26)
    at new _default (directive_manager.js:6)
    at new DOMElement (dom_element.js:12)
    at Function.value (dom.js:36)
    at Component.get (index.js:56)
    at Component.value (index.js:272)
    at Component.value (index.js:246)
    at Component.value (index.js:182)
    at Component.value (index.js:158)
    at Connection.value (index.js:30)
index.blade.php

   <div id="results-products" class="results-products">
        <livewire:charts-products>
    </div>

....
<script>
...
var product= fetchData(url);
window.livewire.emit('set:product', product)
...
</script>
<div>
    @isset($product)
    @foreach ( $product->category as $category)
    <div class="card">
        <div class="card-header">
            <h4>Product category</h4>
        </div>
    </div>
    @endforeach
    @endisset

</div>
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Product;

class ChartsProducts extends Component
{

    public $products;

    protected $listeners = [
        'set:product' => 'setProduct'
    ];

    public function render()
    {
        return view('livewire.charts-products');
    }


    public function setProduct($product)
    {
        $this->product= Product::find($product);
        //I have checked and the assigned variable is ok
    }


}

....
...
var product=fetchData(url);
window.livewire.emit('set:product',product)
...
图表产品.blade.php

   <div id="results-products" class="results-products">
        <livewire:charts-products>
    </div>

....
<script>
...
var product= fetchData(url);
window.livewire.emit('set:product', product)
...
</script>
<div>
    @isset($product)
    @foreach ( $product->category as $category)
    <div class="card">
        <div class="card-header">
            <h4>Product category</h4>
        </div>
    </div>
    @endforeach
    @endisset

</div>
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Product;

class ChartsProducts extends Component
{

    public $products;

    protected $listeners = [
        'set:product' => 'setProduct'
    ];

    public function render()
    {
        return view('livewire.charts-products');
    }


    public function setProduct($product)
    {
        $this->product= Product::find($product);
        //I have checked and the assigned variable is ok
    }


}

@isset(产品)
@foreach($product->类别为$category)
产品类别
@endforeach
@尾端集
ChartsProducts.php

   <div id="results-products" class="results-products">
        <livewire:charts-products>
    </div>

....
<script>
...
var product= fetchData(url);
window.livewire.emit('set:product', product)
...
</script>
<div>
    @isset($product)
    @foreach ( $product->category as $category)
    <div class="card">
        <div class="card-header">
            <h4>Product category</h4>
        </div>
    </div>
    @endforeach
    @endisset

</div>
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Product;

class ChartsProducts extends Component
{

    public $products;

    protected $listeners = [
        'set:product' => 'setProduct'
    ];

    public function render()
    {
        return view('livewire.charts-products');
    }


    public function setProduct($product)
    {
        $this->product= Product::find($product);
        //I have checked and the assigned variable is ok
    }


}

这与Livewire中dom的行为方式有关。尝试向循环项添加一个键

<div>
    @isset($product)
        @foreach ($product->category as $category)
            <div class="card" wire:key="{{ $loop->index }}">
                <div class="card-header">
                    <h4>Product category</h4>
                </div>
            </div>
         @endforeach
    @endisset
</div>

@isset(产品)
@foreach($product->类别为$category)
产品类别
@endforeach
@尾端集
请参阅文档中的疑难解答

另外,将公共属性从
$products
更改为
$product