将JSON数据从2个不同的文件绑定到智能表

时间:2017-09-27 07:21:50

标签: javascript angularjs json

我想用2个不同的JSON文件填充智能表。使用属性Observable.forkjoin()但它不会绑定。我该怎么做? 请帮帮我

service.ts



import {Injectable} from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class SmartTablesService {
  constructor(private http: Http) {
    
        }
        
        smartTableData = [];
//data/article.json
loadData() {
  console.log('loadData');
  Observable.forkJoin(
  this.http.get('http://192.168.0.100:8000/medical'),
  this.http.get('http://192.168.0.100:8000/cost'))
  .subscribe((data) => {
          setTimeout(() => {
              
              var contactData = [];
              $.each(data.map(res => res.json()), function (key, value) {
      //alert(data);
                //  alert(value.year);
              var tempData = value;
              alert(tempData.year);


                

                  contactData.push(tempData);
              });
              //alert(tempData.year);
              this.smartTableData = contactData;
          }, 1000);
      });
}
getData(): Promise<any> {
  console.log("Promise");
  this.loadData();
  return new Promise((resolve, reject) => {
      setTimeout(() => {
          console.log(this.smartTableData);
          resolve(this.smartTableData);
      }, 3000);
  });
}
}
&#13;
&#13;
&#13;

医疗

&#13;
&#13;
[
	{
        "year": 2013,  
        "doctor": "Dr. Smith", 
        "illness": "Flu", 
        "apptdate": "3/12/2013",
		"details":"Patient had flu for 5 days. No medicines prescribed"
	},
	{
        "year": 2014,  
        "doctor": "Dr. ram", 
        "illness": "fever", 
        "apptdate": "31/12/2013",
		"details":"Patient had flu for 5 days. No medicines prescribed"
	}
]
&#13;
&#13;
&#13;

成本

&#13;
&#13;
[
	{
        "year": 2013,  
        "cost": 100
	},
	{
        "year": 2014,  
        "cost": 300
	}
]
&#13;
&#13;
&#13;

如何将这两个日期绑定到智能表?当我使用npm运行时,它显示文件中的行数。但是不会在指定的列中显示内容..所以请帮助我 enter image description here

0 个答案:

没有答案