mardi 17 octobre 2017

Delete an arrayItem nested in an object

i am pretty new to ember, but was thrown into a project. I want to delete an Object within an JSON array that's part of another object. The object may look like this:

{
    "id": 0,
    "title": "My POI tile 1",
    "description": "My POI description. Lorem ipsum...",
    "category": "POI Category",
    "longitude": 5.38383838,
    "latitude": 5.38383838,
    "radius": 1000,
    "rating": {
        "count": 30,
        "average": 3.5,
        "reviews": [
            {
                "username": "Mark Medesso",
                "date": "2012-04-23T18:25:43.511Z",
                "headline": "My headline",
                "text": "My text. Lorem ipsum dolor...",
                "rating": 3
            },
            {
                "username": "Mark Medesso",
                "date": "2012-04-23T18:25:43.511Z",
                "headline": "My headline",
                "text": "My text. Lorem ipsum dolor...",
                "rating": 3
            }
        ]
    }

I want to delete/edit/add reviews to objects like that. My delete looks like this:

actions: {
delete() {
  let self = this;
  var localCopy = this.get('model');
  this.get('modal')
    .create("Wirklich den Review von " + this.model.get('username') + "löschen?")
    .header("Achtung")
    .confirmActions(function() {
      localCopy.destroyRecord().then(function() {
        self.router.send("sessionChanged");
      });
    })
    .modal('show');
}

but i get a 404 when I try to that.

cannot DELETE /poi-reviews/140

How can I delete an object(a review) without it having an ID? Both Poi and Review have a relationship Poi.js:

reviews: DS.hasMany('poi-review'),

poi-review.js:

poi: DS.belongsTo('poi')

Since I am on a single page (viewing the Review) I don't know how to identify the Review i want to delete...




Aucun commentaire:

Enregistrer un commentaire