В моем ионном проекте я хочу получить строки из таблицы базы данных postgreSql, а затем присвоить строки элементу []: currentItems.
Я проверяю строки возврата из postgreSql, этоимеет формат:
[
anonymous
{
name: jack,
email: jack@gmail.com
}
anonymous
{
name: mark,
email: mark@gmail.com
}
]
, однако, когда я назначаю его элементу []: currentItems, я получаю сообщение об ошибке: Тип ошибки машинописного типа 'ArrayBuffer' не может быть назначен типу 'Item [] '.
Ниже приведены части моего иноичного кода:
item.ts:
export class Item {
constructor(fields: any) {
// Quick and dirty extend/assign fields to this model
for (const f in fields) {
// @ts-ignore
this[f] = fields[f];
}
}
}
list-master.ts:
export class ListMasterPage {
currentItems: Item[];
params: { uid: string } = {
uid: "test"
};
constructor(public navCtrl: NavController,
public items: Items,
public modalCtrl: ModalController,
public globalvar: GlobalvarProvider,
public toastCtrl: ToastController) {
this.params.uid = this.globalvar.userIdentifier
this.items.query(this.params).subscribe((resp) => {
/* here assign the received rows from database to the currentItems */
this.currentItems = resp;
}, (err) => {
});;
}
items.ts
export class Items {
constructor(public api: Api) { }
query(params?: any) {
/* here get the rows from the postgresql database, I have confirmed the data received is in the format mentioned in above question description */
return this.api.get('getfriends', params);
}
add(item: Item) {
}
delete(item: Item) {
}
}
Спасибо