大佬教程收集整理的这篇文章主要介绍了Laravel livewire 在附加后看不到渲染更新,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 livewire 组件在一个页面上呈现两个列表。我在左侧列表中有一个按钮,可以使用 attach 将该项目添加到右侧列表(多对多)关系中。这是有效的,但没有重新呈现正确的列表。然后,当我单击左侧列表中的过滤器时,右侧列表会重新呈现显示新附加的项目。当我执行 attach 方法时,似乎没有调用 render() ,或者它正在再次调用 render 以获取新关系?我也尝试从 attach 方法调用 $this->render,但这没有帮助。
public function render()
{
$items = item::with('status')
->where(function($query){
$query->when(!empty($this->SELEctedStati),function ($query) {
$query->whereHas('status',function ($query) {
$query->whereIn('ID',$this->SELEctedStati);
})->orWhereDoesntHave('status');
});
})
->get();
$testItems = $this->test->items;
//dd($testItems);
return vIEw('livewire.items-source',[
'SELEctedStati' => $this->SELEctedStati,'statuses' => $this->status,'items' => $items,'testItems' => $testItems
]);
}
public function filterStatus($ID){
if (($key = array_search($ID,$this->SELEctedStati)) !== falsE) {
unset($this->SELEctedStatI[$key]);
} else {
$this->SELEctedStatI[]=$ID;
}
session(['status'=>$this->SELEctedStati]);
}
public function addToTest($ID){
//attach the given item to the test
$this->test->items()->attach($ID);
dd($this->test->items);
}
public function removeFromTest($ID){
//detach the given item from the test
$this->test->items()->detach($ID);
}
将项目附加到测试集合刷新模型后,使用新数据对其进行补充
public function addToTest($id){
//attach the given item to the test
$this->test->items()->attach($id);
$this->test->refresh();
}
以上是大佬教程为你收集整理的Laravel livewire 在附加后看不到渲染更新全部内容,希望文章能够帮你解决Laravel livewire 在附加后看不到渲染更新所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。