Angular 2 ag-grid动态JSON数据未加载

时间:2017-03-31 05:08:05

标签: angular typescript ag-grid ag-grid-ng2

ngOnInit(){
    this.gridOptions = {};
    this.gridOptions.rowData = [];

    this.gridOptions.rowData = [
      {configName: 1, configName1: "Jarryd", configName2: "Hayne", configName3: "tttttt", configName4: "rrrtttt",
       configName5:"drrrrrr"}];
}

硬编码值正在表中加载。但是内部服务动态值没有加载。

this.service.getData(fields).subscribe(data => {
    data.be.forEach(element => {

        let tableData = {configName: element.configName, configName1: element.configName1, configName2: element.configName2, configName3: element.configName3, configName4: element.configName4, configName5:element.configName5}

        this.gridOptions.rowData.push(tableData )
    }
}

2 个答案:

答案 0 :(得分:0)

我认为最好创建一个内部列表@

configOptions:string[];

this.service.getData(fields).subscribe(data => {
data.be.forEach(element => {

    let tableData = {configName: element.configName, configName1:   element.configName1, configName2: element.configName2, configName3: element.configName3, configName4: element.configName4, configName5:element.configName5}

    this.configOptions.push(tableData );
     this.gridOptions.api.setRowData(this.configOptions);
}
}

答案 1 :(得分:0)

使用类似问题检查Take a look at this post, it might help you.主题。看来你更新ag-grid的方法是不正确的。