我想用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;
医疗
[
{
"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;
成本
[
{
"year": 2013,
"cost": 100
},
{
"year": 2014,
"cost": 300
}
]
&#13;