代码之家  ›  专栏  ›  技术社区  ›  navy1978

如何使用REST调用的结果动态初始化CellEditor

  •  -1
  • navy1978  · 技术社区  · 7 年前

    我正在开发一个使用Angular和Ag网格的应用程序。

      columnDefs = [
            ...
            { 
              headerName: 'LANG', field:'lang', 
              autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true,
              cellEditor : 'agSelectCellEditor',
              cellEditorParams : ['English', 'Spanish', 'French', 'Portuguese', '(other)'];
    
    
            },
           ...
    
            ];
    

    所以一切都很好,在编辑模式下,我得到了带有不同选项的组合框(“英语”、“西班牙语”、“法语”、“葡萄牙语”、“其他”)。 我的问题是,我需要让这些选项调用REST WS。

    因此,我尝试在我的组件(optionValues)中定义一个变量,并用“ngonit”方法填充它,如下所示:

    optionValues :  any;
    
    columnDefs = [
            ...
            { 
              headerName: 'LANG', field:'lang', 
              autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true,
              cellEditor : 'agSelectCellEditor',
              cellEditorParams : this.optionValues,
    
    
            },
           ...
    
            ];
    
    ngOnInit(){
      this.optionValues = this.http.get('http://localhost:8002/myservice');
    
    }
    

    你能帮帮我吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   ABOS    7 年前

    您可以在http中初始化网格设置,

    this.http.get(...).subscribe(v=>{
      this.gridOptions = {
        columnDefs: [...]
      };
      this.optionValues=v;
    });