E
E
elailasou2015-06-22 16:29:13
JavaScript
elailasou, 2015-06-22 16:29:13

backbone. How to change nested property?

The Apps collection has App models.
Models have an array property offers with a status property.
How to change the value of the status property of the offers array property with a specific id?

[
  {
    "id": "11",
    "offers": [
      {
        "id": "118",
        "app_id": "11",
        "offer": {
          "wells": {
            "artesian": [],
            "sand": [
              {
                "app_id": 11,
                "well_type": "sand",
                "tube": "1",
                "price": "1",
                "warranty": "1",
                "cid": "c14"
              }
            ]
          },
          "comment": "",
          "id": 11
        },
        "time": "2015-06-22 15:46:25",
        "comment": "",
        "status": "0",
        "refuse_reason": ""
      },
      {
        "id": "119",
        "app_id": "11",
        "offer": {
          "wells": {
            "artesian": [],
            "sand": [
              {
                "app_id": 11,
                "well_type": "sand",
                "tube": "1",
                "price": "1",
                "warranty": "1",
                "cid": "c12"
              }
            ]
          },
          "comment": "",
          "id": 11
        },
        "time": "2015-06-22 15:54:10",
        "comment": "",
        "status": "0",
        "refuse_reason": ""
      }
    ]
  },
  {
    "id": "10"
  },
  {
    "id": "4"
  }
]

Maybe I write confusingly, I will explain if that. Thanks in advance.
In other words, how do I do
things.get(thing_id).get('offers').get(offer_id)
Or
things.get(thing_id).get('offers').where({id: offer_id})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-06-22
@junk1114

Use plugin. For example Backbone-relational.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question