私は自分の関数にidを渡すときに人の名前を返す関数を作りたいと思います。ここで私がやったものだ。この機能によって呼び出されオブジェクトのパラメータを返します
nameOfPerson(personjson, personId){
let id = personId;
let json = personjson.json();
let data = [];
//console.log("id in nameOfPerson method " + id);
//console.log("json in nameOfPerson method " + JSON.stringify(json))
for (let person of json){
let newPerson = new Person()
newPerson.text = person.firstName + ' ' + person.lastName,
newPerson.id = person.id
if (id == newPerson.id){
data.push(newPerson.text)
}
console.log("data on nameOfPerson method " + JSON.stringify(data))
return JSON.stringify(data);
}
}
:
//parsingFunction
parseAppointment(appointmentJson) {
let data = new Array();
let json = appointmentJson.json()
for (let appointment of json) {
let newAppointment = new Appointment()
newAppointment.text = appointment.reason +' '+ this.personsService.getPersonNamebyId(appointment.personId), // this.personsService.getPersonNamebyId(appointment.personId)
newAppointment.id = appointment.id,
newAppointment.ownerId = appointment.personId,
newAppointment.startDate = appointment.date,
newAppointment.endDate = this.add30mnTo(appointment.date),
data.push(newAppointment);
}
console.log(data)
return data
}
をしてここに呼ばれる::
getPersonNamebyId(personId): Promise<Person[]> {
return this.http.get(this.PersonsUrl)
.toPromise()
.then(response => this.nameOfPerson(response, personId))
.catch(this.handleError)
}
と、この1はここに呼ばれ
getAppointments(): Promise<Appointment[]> {
return this.http.get(this.AppointmentUrlGet)
.toPromise()
.then(response => this.parseAppointment(response))
.catch(this.handleError);
}
全体の目的は、このオブジェクトを変換:人物のオブジェクトの
[
{
id: "bc127c74-377b-4ea6-925a-3dd5e0227482",
reason: "testing",
date: "2017-06-22T14:59:55.000Z",
personId: "8090210d-e154-4db0-96c1-42688f45971a"
},
{
id: "bc127c74-377b-4ea6-925a-3dd5e0227482",
reason: "testing02",
date: "2017-06-22T14:59:55.000Z",
personId: "8090210d-e154-4db0-96c1-42688f45971a"
}
]
(ID = appointment.id、テキスト=理由+ ownernameに)私は私のgetPersonById関数に所有者/ person.idを使用する理由です。
私は私のコンソールログにPERSONID
に取り付けた人物の名前を取得したいと思い、それはまた、[オブジェクトのオブジェクト]ない人の名前... (予定のセルに同じこと言います)
私の間違いがどこにあるか教えてください。
非常
console.log(データ)を実行すると、givオブジェクトオブジェクト – error404
'nameOfPerson'メソッドの中で、配列の最初のオブジェクトに戻ります。そこに間違いがありますか?あなたはアレイ全体を決して通過しないようです。また、 'getPersonNamebyId'メソッドをどのように呼び出すのかを投稿できますか?その人の名前はどこに見えますか? –
あなたの助けを借りてお礼を編集しました – moonshine