0

I'm having trouble changing the location $id on this Backbone model.

{
"approved": null,
"caption": "This is my photo!",
"created": 1393537913,
"location": {
        "_id": {
                "$id": 5
        },
        "address1": "155 West Street",
        "city": "Bangkok",
        "country": "THA",
        "latitude": "13.136",
        "longitude": "100.2068",
        "postalCode": "10330",
        "region": "AP"
        }
}

I've tried:

model.set({"location":{"_id":{"$id": 6}}})

But that obviously overwrites the entire location object.

model.set({"location._id":{"$id":6}})

Creates a new attribute on the model, "location._id".

So, how can I dig in to the location to change that attribute?

ztnark
  • 329
  • 1
  • 2
  • 10

1 Answers1

0

You can do like this :

var location = model.get('location');
location._id = { "$id": 6 };
Rida BENHAMMANE
  • 4,111
  • 1
  • 14
  • 25