Angular 2-要在ag网格中显示的JSON.stringify()对象

Angular 2-要在ag网格中显示的JSON.stringify()对象,json,angular,object,stringify,Json,Angular,Object,Stringify,我有ag网格,从服务中我得到的数据显示在网格中,如下所示: constructor( private codeService: CodeService ) { this.columnDefs = [ { headerName: "Name", field: "name"}, { headerName: "Property", field: "properties", editable: true },

我有ag网格,从服务中我得到的数据显示在网格中,如下所示:

constructor( private codeService: CodeService ) {
        this.columnDefs = [
                 { headerName: "Name", field: "name"},
                 { headerName: "Property", field: "properties", editable: true },
                            ];
    }

    ngOnInit() {
        this.codeService.getCodeType( this.name ).subscribe(
                response => { this.handleSuccess( response ); },
                error => { console.error( error ); });

    }

    handleSuccess( aaTypes ) {
        var data = [];
        aaTypes.forEach( ( aaType ) => {
            var entriesForType = [];
            entriesForType.push( aaType );    
                if ( entriesForType.length > 0 ) {
                    entriesForType.forEach( entry => data.push( entry ) );
                    this.data = data;
                    if(this.gridOptions.api !== null){
                        this.gridOptions.api.setRowData( data );
                    }
                } 
        });
    }
我的ts代码如下所示:

constructor( private codeService: CodeService ) {
        this.columnDefs = [
                 { headerName: "Name", field: "name"},
                 { headerName: "Property", field: "properties", editable: true },
                            ];
    }

    ngOnInit() {
        this.codeService.getCodeType( this.name ).subscribe(
                response => { this.handleSuccess( response ); },
                error => { console.error( error ); });

    }

    handleSuccess( aaTypes ) {
        var data = [];
        aaTypes.forEach( ( aaType ) => {
            var entriesForType = [];
            entriesForType.push( aaType );    
                if ( entriesForType.length > 0 ) {
                    entriesForType.forEach( entry => data.push( entry ) );
                    this.data = data;
                    if(this.gridOptions.api !== null){
                        this.gridOptions.api.setRowData( data );
                    }
                } 
        });
    }

正如你所看到的。。。属性实际上是对象,它在图1的网格中显示出来……我的问题是,我有没有办法把“属性”字符串化,这样它就会显示为字符串而不是对象。。如果它显示类似“{location:0,color;255}”的内容,我就可以了

将valueFormatter添加到columnDefs并创建格式化程序:

constructor( private codeService: CodeService ) {
    this.columnDefs = [
             { headerName: "Name", field: "name"},
             { headerName: "Property", field: "properties", valueFormatter: jsonFormatter, editable: true },
                        ];
}

function jsonFormatter(d) {
     return JSON.stringify(d);
}

你试过这个吗?我见过这个,但我不太明白我该如何在我的案例中应用,但似乎这正是我所需要的@萨吉塔兰