angular - PrimeNG TypeError "this._activeIndex.includes" 不是函数
问题描述
我有一个使用手风琴的组件。我希望启用多个选项卡和自定义 activeIndex。这是我的代码:
<p-accordion [activeIndex]="index" [multiple]="true">
<p-accordionTab header="1st tab">
1st tab content
</p-accordionTab>
<p-accordionTab header="2nd tab">
2nd tab content
</p-accordionTab>
</p-accordion>
这是我的组件类
@Component({
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
})
export class PanelComponent implements OnInit {
index:number = 1;
constructor() {
}
ngOnInit() {
//this.index = 0;
}
}
如果我想同时包含 [activeIndex] 和 [multiple],就会出现问题。任何想法为什么会发生这种情况?
我使用 PrimeNG 7 和 angular 7
解决方案
文档说:
活动选项卡的索引或以编程方式更改选定选项卡的索引数组。
这是设置activeTabs的相关代码_activeIndex
updateSelectionState() {
if (this.tabs && this.tabs.length && this._activeIndex != null) {
for (let i = 0; i < this.tabs.length; i++) {
let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
let changed = selected !== this.tabs[i].selected;
if (changed) {
this.tabs[i].animating = true;
}
this.tabs[i].selected = selected;
this.tabs[i].selectedChange.emit(selected);
}
}
}
因此,对于多个选项卡,您应该使用索引数组,而不是数字。
@Component({
selector: 'app-panel',
templateUrl: './panel.component.html',
styleUrls: ['./panel.component.css']
})
export class PanelComponent implements OnInit {
indices: number[] = [1, 2];
constructor() {
}
ngOnInit() {
//this.index = 0;
}
}
如果您想知道,this._activeIndex.includes(i)
这就是您的错误的来源。
推荐阅读
- angular - 捕获 DOM 中存在的 4 个详细信息标签并将它们标识为一个
- virtualbox - Virtualbox 在 vmware esxi 服务器的嵌套虚拟化中不起作用,如何解决?
- git - 合并从主分支恢复合并的发布分支会将恢复合并到主分支?
- javascript - 改变所有图片的src属性值
- javascript - 我想在 Postman 控制台中记录所有错误消息
- jquery - Footable jQuery table - 检索变量中的计数 {TR} 值
- javascript - 初始化集合后查找模型返回空数组
- arrays - 该元素隐含类型为“any”,因为类型“string”的表达式不能用于索引该类型
- linux - alt_space_toggle 在 xkb-switch 中不起作用
- javascript - 大量数据(500K 记录)的 JavaScript 数组需要时间来搜索和添加