我是angular4初学者,我想询问有关订阅数据的信息。
该组件具有makeTableInfo()方法。 这个makeTableInfo()方法是使primeng可以自动调整。
我想在makeTableInfo中获取列数据和行数据,但这些列和行未定义。
我认为makeTableInfo()方法在获取列数据和列数据之前运行。
所以我的猜测是等到检索列数据和行数据。
但我还没有想到解决这个问题。
你能给我一些建议来实现我的目标吗?
np.equal(mar, 0)
这是tableservice
export class SerializeComponent implements OnInit, OnChanges {
tableSetting: TableSetting;
settingA: TableSetting;
settingB: TableSetting;
rows: Bom[] = [];
cols: ColumnSettings[] = [];
userId: string;
url: string;
area: string;
constructor(
private notifyService: NotifyService,
private router: Router,
private tableService: TableService,
private localStorageService: GridService
) {}
makeTableInfo(
userId,
url,
area,
rowDataPath,
columnDataPath,
reorderableColumns,
resizableColumns,
paginator,
paginatorRows
): any {
let rows;
let columns;
this.tableService.setColumnDataPath(columnDataPath);
this.tableService.setRowDataPath(rowDataPath);
this.tableService.getRowData().subscribe((rowData) => {
⬇︎⬇︎⬇︎⬇︎ can't get rows ⬇︎⬇︎⬇︎⬇︎
rows = rowData;
this.tableService
.getColumnSetting()
.subscribe((initData) => {
⬇︎⬇︎⬇︎⬇︎⬇︎ can't get columns ⬇︎⬇︎⬇︎⬇︎
columns = initData;
});
return new TableSetting(
userId,
url,
area,
resizableColumns,
reorderableColumns,
columns, // ← undefined
rows, // ← undefined
paginator,
paginatorRows,
columnDataPath
);
});
}
ngOnInit(): void {
this.userId = 'user01';
this.url = this.router.url;
const areaA = 'upper';
const rowDataPathA = 'aaa/aaa/data.json';
const columnDataPathA = 'bbb/bbb/column.json';
const reorderableColumnsA = false;
const resizableColumnsA = false;
const paginatorA = true;
const paginatorRowsA = 10;
this.settingA = this.makeTableInfo(
this.userId,
this.url,
areaA,
rowDataPathA,
columnDataPathA,
reorderableColumnsA,
resizableColumnsA,
paginatorA,
paginatorRowsA
);
}
}
答案 0 :(得分:0)
您有错误,因为变量:当数据从服务器返回时,行和列不再存在。将它们移动到SerializeComponent的顶部(或使用您已有的变量)。在行和列变量之前的makeTableInfo中添加此项。吸引他们 e.g:
export class SerializeComponent implements OnInit, OnChanges {
tableSetting: TableSetting;
settingA: TableSetting;
settingB: TableSetting;
rows: Bom[] = [];
cols: ColumnSettings[] = [];
userId: string;
url: string;
area: string;
constructor(
private notifyService: NotifyService,
private router: Router,
private tableService: TableService,
private localStorageService: GridService
) {}
makeTableInfo(
userId,
url,
area,
rowDataPath,
columnDataPath,
reorderableColumns,
resizableColumns,
paginator,
paginatorRows
): any {
this.tableService.setColumnDataPath(columnDataPath);
this.tableService.setRowDataPath(rowDataPath);
this.tableService.getRowData().subscribe((rowData) => {
this.rows = rowData;
this.tableService
.getColumnSetting()
.subscribe((initData) => {
this.columns = initData;
});
return new TableSetting(
userId,
url,
area,
resizableColumns,
reorderableColumns,
columns, // ← undefined
rows, // ← undefined
paginator,
paginatorRows,
columnDataPath
);
});
}
.....