[英]PrimeNG DataTable programmatically select row checkbox
Hi I will be having a 'selectedrow' array list in my ngOninit().嗨,我将在我的 ngOninit() 中有一个“selectedrow”数组列表。 I want to make selection to all row checkboxes which is in 'selectedrow' variable.
我想对“selectedrow”变量中的所有行复选框进行选择。
https://stackblitz.com/edit/github-4vvqp4-xbrzdy?file=src%2Fapp%2Fapp.component.html https://stackblitz.com/edit/github-4vvqp4-xbrzdy?file=src%2Fapp%2Fapp.component.html
you want to push some card in to selectedCars
.您想将一些卡片推入
selectedCars
。
but selectedCars
is not a list, because of that you see ERROR: Cannot read property 'push' of undefined
但
selectedCars
不是列表,因此您会看到 ERROR: Cannot read property 'push' of undefined
to fix it just make selectedCars
as list (with default value)要修复它,只需将
selectedCars
作为列表(具有默认值)
selectedCars:any[] = [];
You are declaring the selectedCars as type any
but you are not assigning it as empty array,so initially the value of selectedCars
gets undefined that's why the default selected item is not binding to the table.您将 selectedCars 声明为
any
类型,但没有将其分配为空数组,因此最初selectedCars
的值未定义,这就是默认选定项未绑定到表的原因。 change the code like this像这样更改代码
selectedCars:any[] = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.