1
Ich versuche, wie dies ein param-ID auf einem Reaktions Objekt zu setzen:wirklich seltsame Sache mit aurelia Router params
reaction: { message_id: ""};
async activate(params) {
alert(params.id);
this.reaction.message_id = params.id;
}
Der Alarm korrekt ist, so dass es richtig fordert. Aber dann erhalte ich in meiner Konsole:
ERROR [app-router] TypeError: Cannot set property 'message_id' of undefined
Edit:
import { HttpClient, json } from "aurelia-fetch-client"
import { autoinject } from "aurelia-framework"
import { Router } from 'aurelia-router'
@autoinject
export class message {
message: { reactions: Reaction[], id: "" };
editing: boolean;
reaction: Reaction;
constructor(private http: HttpClient, private router: Router) {
this.editing = false;
}
created() {
this.getMessage();
}
async activate(params) {
alert(params.id);
this.reaction.message_id = params.id;
}
getMessage() {
this.http.fetch('message/show', {
body: json(this.router.currentInstruction.params.id)
})
.then(response => response.json())
.then(data => {
this.message = data;
});
}
update() {
this.http.fetch('message/update', {
body: json(this.message)
})
.then(response => {
if (response.status == 200) {
swal({
title: "Bericht succesvol geupdatet",
type: "success",
showConfirmButton: false,
timer: 2000
});
}
this.editing = false;
});
}
destroy() {
swal({
title: 'Weet u het zeker?',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Ja verwijder dit bericht',
cancelButtonText: 'Stop!',
confirmButtonColor: '#002e5b',
}, (isOk) => {
if (isOk) {
this.http.fetch('message/destroy', {
body: json(this.message)
}).then(data => {
swal({
title: 'Verwijderd',
text: 'Het bericht is succesvol verwijderd',
type: 'success',
showConfirmButton: false,
timer: 3000
});
});
this.router.navigate("/dashboard");
}
});
}
post() {
this.message.reactions.push(this.reaction);
this.http.fetch('reaction/store', {
body: json(this.reaction)
}).then(response => {
if (response.status == 200) {
swal({
title: "Reactie succesvol aangemaakt",
type: "success",
showConfirmButton: false,
timer: 2000
});
this.reaction = {};
}
});
}
}
export class Reaction {
message_id: number;
account_id: number;
reaction: string;
}
"Reaktion" muss ein Mitglied der Klasse sein. Ihr Code ist falsch, daher ist der Fehler sinnvoll. Versuchen Sie, die Reaktion als Mitglied der Klasse zu deklarieren, wie zum Beispiel 'reaction: {message_id:" "};' –
@FabioLuz ist ein Mitglied der Klasse. Einfach vereinfacht, damit es leichter zu verstehen ist. – Jamie
hmm kannst du wie die ganze klasse? –