Go through an object with Vue2.js

1

My question is how do I access the parish array ...

try the HTML to do:

{{@beneficiario.parroquia.parroquia}} y and gives this error:

  

Error in render: "TypeError: Can not read property 'parish' of undefined"

HTML                    

JSON

          
            @{{ beneficiario.parroquia.parroquia}}
          
          
            @{{ $data }}
          
        

JSON:

   "beneficiario": {
    "id": 1,
    "cedula": "V-14748547",
    "nombres": "Pepito",
    "apellidos": "¨Pregunton",
    "email": "[email protected]",
    "telefono": "02128477447",
    "direccion": "La Palomera",
    "parroquia_id": 617,
    "parroquia": {
      "id": 617,
      "parroquia": "BARUTA",
      "municipio_id": 181,
      "municipio": {
        "id": 181,
        "municipio": "BARUTA",
        "estado_id": 13,
        "estado": {
          "id": 13,
          "estado": "MIRANDA",
          "activo": 0
        }
      }
    },
    "canaimas": [
      {
        "id": 1,
        "modelo": "MG10T",
        "deleted_at": null,
        "activo": 1,
        "pivot": {
          "beneficiario_id": 1,
          "canaima_id": 1,
          "serial_canaima": "454DS5FDFD55",
          "descripcion": "esta rayada"
        }
      }
    ]
  }
}

and the VUE.js is:

 
    new Vue({
     el: "#beneficiario",
     data: {
      cedula: '',
      beneficiario: []
    },
    methods:{
      searchB: function(){
        var url = '../../getCedulaBeneficiario/' + this.cedula;
        axios.get(url).then(response => {
          this.beneficiario = response.data;
          console.log(response.data);
        });

      }
    }
  });

    
asked by Edward Flores 19.01.2018 в 21:31
source

2 answers

1

I told you before ... I could guide you with your answer .. I did this!

declare an array for each one! ..

new Vue({
 el: "#beneficiario",
 data: {
  cedula: '',
  beneficiario:[],
  parroquia:[],
  municipio:[],
  estado:[]
},
methods:{
  searchB: function(){
    var url = '../../getCedulaBeneficiario/' + this.cedula;
    axios.get(url).then(response => {
      this.beneficiario = response.data;
      this.parroquia = response.data.parroquia;
      this.municipio = response.data.parroquia.municipio;
      this.estado = response.data.parroquia.municipio.estado;
      console.log(response.data);
    });

  }
}

});

    
answered by 19.01.2018 в 21:50
0

You can access the attributes of the array using []:

var nombre_parroquia = beneficiario[beneficiario[parroquia]];
    
answered by 19.01.2018 в 21:35