ng2-smart-table:json中的数据

时间:2019-10-18 22:56:21

标签: angular ng2-smart-table

我想将json数据链接到ng2-smart-table

我的json返回很多数据

"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” 你能帮我吗?

1 个答案:

答案 0 :(得分:0)

如果您碰巧有机会在这里查看documentation,这实际上很简单。

在这里,尝试一下:

n + m

在您的模板中:

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));
  }
}

  

这是您推荐的Working Sample StackBlitz