本地 json 文件和 ng2-smart-table

local json file and ng2-smart-table

如何加载本地json文件并在ng2-smart-table中显示数据?

这是我当前用于从本地 json 文件检索数据的代码:

public getList() {
    return this.http.get('./assets/data/line-items.json')
        .toPromise()
        .then(response => response.json())
        .then(json => {
            console.log('data', json.items);
            return json.items;
        });
}

并且我想将所有数据传递给 ng2-smart-table

中的 [source]
<ng2-smart-table [settings]="settings" [source]="data"></ng2-smart-table>

getList return 一个承诺,所以你必须这样做:

 this.getList().then(data=>{
   this.data = data;

});