このコードでは、tripID
とNoteID
をウェブサービスから試してみて、それを他の関数に格納してからtrips[i].noteID
キャッシュ他のWebサービスが、休閑エラーから起こる:オブジェクトの配列から新しいデータにデータを格納しようとするときにエラーを解決するには
public trips= [{ "Token" : "" ,
"UDI" : "",
"tripID" : "",
"NoteID":"",
"START_ADDRESS":"",
"END_ADDRESS":"",
"NAME":"",
"PHONE":"",
"COST":"",
}];
GetTrips(){
let i = 0;
let Url='http://mysitesite/gettrip/'+this.UDI+'/'+this.Token;
console.log(Url);
this.http.get(Url)
.map(res => res.json())
.subscribe(data => {
console.log(data);
for(let note of data.notes) {
this.trips[i].Token=this.Token;
this.trips[i].UDI=this.UDI;
this.trips[i].NoteID=note.ID;
this.trips[i].tripID=note.TRIP;
i++;
}
console.log(this.trips);
}
});
}
エラー:
例外:未定義
の設定はできませんプロパティ 'トークン'例外:
未定義例外のプロパティ 'UDI' を設定することはできません:property'NoteIDを設定することはできません」
未定義例外:設定できませんプロパティ '未定義
のtripID' 更新1 : これで@toskvポストの後、最新の変更:
for(let note of data.notes) {
let newTrip = {
Token: this.Token,
UDI: this.UDI,
NoteID: note.ID,
tripID: note.TRIP,
START_ADDRESS :null,
END_ADDRESS:null,
NAME:null,
PHONE:null,
COST:null,
};
this.trips.push(newTrip);
}
console.log(this.trips);
this.trips =this.trips.slice(1);
console.log(this.trips.length);
}
あなたは本当に配列がjsの中でどのように機能するかについて少し読んでください。今すぐあなたは未定義です。 – toskv