Access the attribute inside my json
Access the attribute inside my json
klermann
Posts: 277Questions: 67Answers: 1
Hello, how can I access the attribute inside my json. I tried in many ways, but not achieved so far ...
{
"draw": 0,
"recordsTotal": 8,
"recordsFiltered": 7,
"dataReceitas": null,
"data": [{
"id": 9,
"descricaoReceita": "Receita 9999",
"dataReceita": {
"year": 2017,
"month": "AUGUST",
"dayOfMonth": 8,
"dayOfWeek": "TUESDAY",
"era": "CE",
"dayOfYear": 220,
"leapYear": false,
"monthValue": 8,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"valorReceita": 5000.00,
"receitaFixa": true,
"receitaFixaQuantidade": 1,
"receitaFixaTempo": "DIAS",
"repetirLancReceita": false,
"repetirPorPeriodo": "MENSAL",
"pagamento": false,
"addObservacao": "dgdg",
"**tipoReceitas**": [{
"id": 5,
"**nome**": "Tipo 5",
"corTipoReceita": "#AFFJKL",
"nomeTipoReceita": "Tipo 5"
}],
"minhasContas": [{
"id": 1,
"nome": "Contas 1",
"dataAcesso": {
"year": 2017,
"month": "JANUARY",
"dayOfMonth": 1,
"dayOfWeek": "SUNDAY",
"era": "CE",
"dayOfYear": 1,
"leapYear": false,
"monthValue": 1,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"saldoAnterior": 0.00,
"saldoAtual": 5600.00,
"saldoFinal": 2520.00,
"tipo": "POUPANCA",
"cor": "#5d4aas",
"dashBoard": false
}],
"etiquetas": [{
"id": 156,
"nome": "fghfhfgh",
"minhasReceitas": null
}],
"cor": "rgb(255, 24, 01, 0.8)"
}, {
"id": 225,
"descricaoReceita": "gfgsd",
"dataReceita": {
"year": 2017,
"month": "AUGUST",
"dayOfMonth": 9,
"dayOfWeek": "WEDNESDAY",
"era": "CE",
"dayOfYear": 221,
"leapYear": false,
"monthValue": 8,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"valorReceita": 5000.00,
"receitaFixa": true,
"receitaFixaQuantidade": null,
"receitaFixaTempo": null,
"repetirLancReceita": false,
"repetirPorPeriodo": null,
"pagamento": false,
"addObservacao": "werwe",
"tipoReceitas": [{
"id": 5,
"nome": "Tipo 5",
"corTipoReceita": "#AFFJKL",
"nomeTipoReceita": "Tipo 5"
}],
"minhasContas": [{
"id": 2,
"nome": "Contas 2",
"dataAcesso": {
"year": 2017,
"month": "FEBRUARY",
"dayOfMonth": 1,
"dayOfWeek": "WEDNESDAY",
"era": "CE",
"dayOfYear": 32,
"leapYear": false,
"monthValue": 2,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
"saldoAnterior": 0.00,
"saldoAtual": 2600.00,
"saldoFinal": 1500.00,
"tipo": "POUPANCA",
"cor": "#5d4aas",
"dashBoard": false
}],
"etiquetas": [{
"id": 157,
"nome": "xcswfswe",
"minhasReceitas": null
}],
"cor": null
}]
}
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Which attribute specifically, and where in the code? I'm not certain what it is exactly you are trying to do I'm afraid.
Allan
I was able to access, it was the "Etiquetas" attribute
How do I access an object inside another object by placing that object accessed inside a select type list in form editor. The item I speak of is marked in bold, => "MinhaContas" => "Nome"
How do I access an object inside another object by placing that object accessed inside a select type list in form editor. The item I speak of is marked in bold, => "MinhaContas" => "Nome"
Use dot notation like you would in plain Javascript - see the
columns.data
documentation for full details. e.g.MinhaContas.Nome
.Allan
Sorry for posts duplicated! My select is displayed without a list!
Can you post a link to a test case showing the issue please?
Thanks,
Allan
Folow link of the application: ec2-34-224-214-123.compute-1.amazonaws.com:8080/demo/receitas
Sorry but I had to change the url:
ec2-52-91-50-157.compute-1.amazonaws.com:8080/financeiro/receitas
Your
listTipoReceitas
function is resolving to be an empty array - see attached image.That is because it is performing an async action:
You could just add
async: false
, but I would suggest you use theupdate()
method of theselect
field type to update the options in its callback.Regards,
Allan
How should i use update() method of the select field type to update the options in its callback. Would it be possible to get the data from this list in the object that populates the datatable to populate this select type list?
I'm lost, can you help me please!
Simply:
inside your
done
function.Allan
I did as directed and the datatable disappeared, disappeared
I did as directed and the datatable disappeared, disappeared
`function listTipoReceitas(){
Allan is it common for all users with this difficulty to display the data from a list from within a json without editor or just this happening to me due to my json format generated by the server?
Allan suggested you put the
editor.field('tipoReceitas').update(listTR);
inside the ajaxdone
function. You placed it outside the function. Try placing it on line 17.Kevin
And not inside the editor?
<?php ??? ?>{
Name: "tipoReceitas"
// placeholder: 'Tipos', "type": "select", "ipOpts": listTipoReceita ()
},
Your function
listTipoReceitas()
is getting a list of options via ajax, correct?What Allan is saying is that the ajax call is asynchronous meaning the script sends the request to the server and continues executing. The function
listTipoReceitas()
sends the ajax request and continues execution which is to returnlistTR
on line 22. The return happens before the ajax response is received and processed by thedone
function. Resulting in an empty array being returned.The update method updates the options for the provided field. Placing the command in the
done
function should update the select options fortipoReceitas
after the ajax call is complete.Kevin
Yup - exactly what Kevin says. You must keep in mind what the first letter of Ajax stands for - asynchronous.
Allan
Unfortunately it has not updated, what can I do more?
Put it outside the
forEach
.Step back and think about it for a moment . You want to pass an array of items to the update function. That array is being constructed in the forEach. It won't be ready until the forEach is finished.
Also you are using:
editor.field('tipoReceitas')
but you have no field called tipoReceitas. You configure Editor thus:You need to use that same name.
Allan
Now I did exactly as you told me, but now the datatable does not seem
` function listTipoReceitas(){
name: 'tipoReceitas',
placeholder: 'Tipos', 'type': 'select', 'ipOpts': listTipoReceitas()
I think you should leave your editor field name as:
name: "tipoReceitas.nome",
And change the update to this:
editor.field('tipoReceitas.nome').update(listTR);
Kevin
The datatable appeared but the empty select
I discovered the error here. This is happening when assembling the list object.
How can I mount this object with the ":" and comma in object:
My code:
listTR[i] = { {label" : "" + nomeTipoReceita + "", "value" : "" + i + ""};
Original:
listEt[0] = { "label": "Etiqueta 1", "value": "1" };
It looks like the way you originally built the array of objects is good.
You can use
console.log(listTR)
right aftereditor.field('tipoReceitas.nome').update(listTR);
to see what was used for the update.I wonder if the
return listTR;
at the end of your function is causing an issue. I would try removing thereturn listTR;
.Kevin
I discovered the error: The error happened because the object of the relationship was coming empty and was giving an error when doing the each, when I found the empty object burst the error, find the data in the table and now select the appeared. Now, you need to treat this object so when it comes empty do not pop the error and continue as usual! Thank you very much for your attention!