1

我正在尝试生成由 ajax 加载的网格(来自我的服务器的 JSON)

什么是简单的等待呢?

如何将异步 json 响应绑定到此网格?

下面的代码是我今天的做法(硬编码)

感谢你

import { Component, OnInit } from '@angular/core';
import { HttpService } from 'services/http.service'

@Component({
    selector: 'my-analytics',
    styleUrls: ['../../../node_modules/@telerik/kendo-theme-default/dist/all.css'],
    template: require('./analytics.component.html')

})
export class AnalyticsComponent implements OnInit {

    private gridData: any[] = [{
        "ProductID": 1,
        "ProductName": "Chai",
        "UnitPrice": 18.0000,
        "Discontinued": false,
        "Category": {
            "CategoryID": 1,
            "CategoryName": "Beverages",
            "Description": "Soft drinks, coffees, teas, beers, and ales"
        }
    }, {
        "ProductID": 2,
        "ProductName": "Chang",
        "UnitPrice": 19.0000,
        "Discontinued": false,
        "Category": {
            "CategoryID": 1,
            "CategoryName": "Beverages",
            "Description": "Soft drinks, coffees, teas, beers, and ales"
        }
    }, {
        "ProductID": 3,
        "ProductName": "Aniseed Syrup",
        "UnitPrice": 10.0000,
        "Discontinued": false,
        "Category": {
            "CategoryID": 2,
            "CategoryName": "Condiments",
            "Description": "Sweet and savory sauces, relishes, spreads, and seasonings"
        }
    }];

    constructor(private http_service: HttpService) { }

    ngOnInit() {

    }
}
4

2 回答 2

1

你可以通过使用 subsribe 来尝试这样

       this.http.get(this.url)
        .map(response => response.json())
        .subscribe(result => {
             this.gridData= result


        },
             err => console.log(err)
        );
于 2016-11-02T09:55:41.407 回答
0

您可以为此目的使用异步管道。检查相应的数据绑定帮助文章

于 2016-10-25T13:18:34.037 回答