Attribute json undefined

0

Good afternoon guys,

I have the problem that I can not access the APPLICATIONS attribute of json , it always returns undefined .

When running console.log(aplic[0]) it prints this json , but if it gives console.log(aplic[0].APLICACOES) it does not show the 4 application child objects.

Does anyone know why this is happening? or what I should do to resolve this problem.

Thank you

function getAplicacoesAtividadesAgricolasBD(idAtividadeAgricola) {
return new Promise((resolve, reject) => {
    const aplicacoes = [];
    db.transaction((tx) => {
        tx.executeSql('SELECT * FROM ATIVIDADE_AGRICOLA_APLICACAO WHERE ID_ATIVIDADE_AGRICOLA = ?',
            [idAtividadeAgricola], (tx, results) => {
                for (let i = 0; i < results.rows.length; i++) {
                    const aplic = results.rows.item(i);
                    aplicacoes.push(aplic);
                }

                resolve(aplicacoes);
            }, () => {
                reject('Erro ao consultar dados. Por favor, tente novamente!');
            });
    });
});


function getDataDBAtividadeAgricolaById(idPropriedade, idAtividadeAgricola) {
return new Promise((resolve, reject) => {
    const aplicacoes = [];
    db.transaction((tx) => {
        tx.executeSql('SELECT * FROM ATIVIDADE_AGRICOLA WHERE (ID_PROPRIEDADE = ?) AND (ID_ATIVIDADE_AGRICOLA = ?)',
            [idPropriedade, idAtividadeAgricola], (tx, results) => {
                for (let i = 0; i < results.rows.length; i++) {
                    const aplic = results.rows.item(i);

                    getAplicacoesAtividadesAgricolasBD(aplic.ID_ATIVIDADE_AGRICOLA)
                        .then(itens => {
                            aplic['APLICACOES'] = itens;
                        });
                    aplicacoes.push(aplic);
                }

                resolve(aplicacoes);
            }, (err) => {
                reject('Erro ao consultar dados. Por favor, tente novamente!');
            });
    });
});

export function visualizarAtividadeAgricolaModal(idPropriedade, idAtividadeAgricola) {
return async (dispatch) => {
    getDataDBAtividadeAgricolaById(idPropriedade, idAtividadeAgricola)
        .then(aplic => {
            console.log(aplic[0]);
            console.log(JSON.stringify(aplic[0]));
            console.log(aplic[0].APLICACOES);
            dispatch({
                type: AGR_AA_SET_ATIVIDADE_AGRICOLA_VIEW,
                data: aplic[0]
            });
        })
        .catch((err) => {
            console.log(err);
            Alert.alert('Atenção!', 'Erro ao consultar dados. Por favor, tente novamente!');
        });
};
    
asked by anonymous 18.10.2018 / 21:59

1 answer

0

O

aplic[0].APLICACOES

contains an array. Therefore it would be necessary to use a map function to display the elements. It would look something like this:

Object.keys(aplic[0].APLICACOES).map((key) => console.log(aplic[0].APLICACOES[key]))
    
14.11.2018 / 21:13