【问题标题】:kendo ui grid with angular 2 and async datasource具有角度 2 和异步数据源的剑道 ui 网格
【发布时间】:2016-10-25 10:32:35
【问题描述】:

我正在尝试生成一个由 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() {

    }
}

【问题讨论】:

    标签: kendo-ui kendo-ui-angular2


    【解决方案1】:

    你可以用subsribe试试这个

           this.http.get(this.url)
            .map(response => response.json())
            .subscribe(result => {
                 this.gridData= result
    
    
            },
                 err => console.log(err)
            );
    

    【讨论】:

      【解决方案2】:

      您可以为此目的使用异步管道。检查相应的数据Binding help article

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-07-17
        • 1970-01-01
        • 1970-01-01
        • 2014-01-04
        • 1970-01-01
        • 1970-01-01
        • 2017-08-20
        相关资源
        最近更新 更多