Collection Nested Backbone

1

I ask for your help to help me get the value of a key that is nested, when I render, it shows me the first level but I do not know how to get to the more internal nodes, the model is:

{
 "ciudadDepartamento": "Bogotá",
 "estadoDepartamento": true,
 "fechaCreacion": "2016-05-12T00:00:00-05:00",
 "id": 1,
 "idFacultad": {
  "ciudadFacultad": "Bogotá",
  "estadoFacultad": true,
  "fechaCreacion": "2016-05-12T00:00:00-05:00",
  "id": 2,
  "nombreFacultad": "Facultad de Ingeniería y Ciencias Básicas"
 },
 "nombreDepartamento": "Ciencias básicas"
}

I want to get the value of nameFaculty

    
asked by Gdaimon 15.05.2016 в 21:50
source

1 answer

1

VIEW DEMO

var JsonGetData = Backbone.Model.extend({
    parse: function (data) {       
        return data.idFacultad;
    }
});

var JsonGetDataResult = Backbone.Collection.extend({
    model: JsonGetData
});

var j = new JsonGetDataResult([{

 "ciudadDepartamento": "Bogotá",
 "estadoDepartamento": true,
 "fechaCreacion": "2016-05-12T00:00:00-05:00",
 "id": 1,
 "idFacultad": {
  "ciudadFacultad": "Bogotá",
  "estadoFacultad": true,
  "fechaCreacion": "2016-05-12T00:00:00-05:00",
  "id": 2,
  "nombreFacultad": "Facultad de Ingeniería y Ciencias Básicas"
 },
 "nombreDepartamento": "Ciencias básicas"
}], { parse: true });

/* Mira en tu consola */
console.log(j.first().get('nombreFacultad'));
// salida: Facultad de Ingeniería y Ciencias Básicas

I have not yet tried backbone.js but I have reported a bit on the API-Integration and I hope this is what you were looking for.

    
answered by 15.05.2016 / 22:47
source