ng2-smart-table:数据来自 json
ng2-smart-table: data from json
我想link我的json数据到ng2-smart-table
我的jsonreturn很多数据
"data":{
"name":"Myname",
"email":"myemail@gmail.com",
"car":[
{
"carId":"99",
"carName":"mycar",
"carBurant":"diesel"
},
{
"carId":"88",
"carName":"mycar2",
"carBurant":"diesel"
},
{
"carId":"77",
"carName":"mycar3",
"carBurant":"diesel",
},
]
}
我想在我的 ng2-smart-table 上安装 "carId" 、 "carName" 和 "carBurant"
你能帮帮我吗?
如果你碰巧有机会看看这里的documentation,其实很简单。
在这里,试一试:
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
settings = {
columns: {
carId: {
title: "Car ID"
},
carName: {
title: "Car Name"
},
carBurant: {
title: "Car Burant"
}
}
};
data;
constructor(private http: HttpClient) {}
ngOnInit() {
this.http.get("assets/user.json").subscribe(user => (this.data = user.car));
}
}
在您的模板中:
<ng2-smart-table
[settings]="settings"
[source]="data">
</ng2-smart-table>
Here's a Working Sample StackBlitz for your ref.
我想link我的json数据到ng2-smart-table
我的jsonreturn很多数据
"data":{
"name":"Myname",
"email":"myemail@gmail.com",
"car":[
{
"carId":"99",
"carName":"mycar",
"carBurant":"diesel"
},
{
"carId":"88",
"carName":"mycar2",
"carBurant":"diesel"
},
{
"carId":"77",
"carName":"mycar3",
"carBurant":"diesel",
},
]
}
我想在我的 ng2-smart-table 上安装 "carId" 、 "carName" 和 "carBurant" 你能帮帮我吗?
如果你碰巧有机会看看这里的documentation,其实很简单。
在这里,试一试:
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
settings = {
columns: {
carId: {
title: "Car ID"
},
carName: {
title: "Car Name"
},
carBurant: {
title: "Car Burant"
}
}
};
data;
constructor(private http: HttpClient) {}
ngOnInit() {
this.http.get("assets/user.json").subscribe(user => (this.data = user.car));
}
}
在您的模板中:
<ng2-smart-table
[settings]="settings"
[source]="data">
</ng2-smart-table>
Here's a Working Sample StackBlitz for your ref.