我试图在角度6中使用多选下拉列表,并从数据库中提取动态内容。但是我发现很难创建用于填充下拉列表的对象数组。这是我的HTML文件,如下所示:
<div>
<ng-multiselect-dropdown
[placeholder]="'custom placeholder'"
[data]="dropdownList"
[settings]="dropdownSettings"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
>
</ng-multiselect-dropdown>
</div>
问题位于.ts文件中。使用我从数据库获得的结果集,我试图创建一个对象数组,但是以[object,object]结尾,因此在下拉列表中显示“无可用数据”。帮助我根据从数据库获得的Resultset创建对象数组。这是我的.ts文件:
export class AdComponent implements OnInit
{
constructor(private adservice: AdService) { }
public salesGroupList :any[]=[];
public sqGroupList :any;
dropdownList: any[]=[];
dropdownSettings:{};
ngOnInit()
{
this.getSalesGroup();//service
}
getSqGroup()
{
this.adjustedsqservice.getSqGroup().subscribe(
data =>
{
this.sqGroupList =data;
for(let i = 0 ; i < this.sqGroupList.length; i++)
{
this.testId= this.sqGroupList[i].SQ_grp_cd;
console.log(this.testId+" test name");
this.test = this.sqGroupList[i].SQ_grp_nm;
let newName = {
item_id:this.testId,
item_text:this.test
};
this.dropdownList.push(JSON.stringify(newName));
}
}
);
this.dropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
itemsShowLimit: 3,
allowSearchFilter: false
};
}
我需要使用html中的多选下拉列表动态显示这些值,但现在由于没有数据可用而出现