I’ve made an app for android, using java, and there is a snippet of the code that I want to implement in my Ionic app, what it does in android is:
I have a Json with nested arrays like so:
{
"total":11,
"dados":[
{
"id":"18",
"cod_id":"6f4922f45568161a8cdf4ad22f6d23",
"id_rm_empresa":"1",
"id_rm_tipo_cliente":"1",
"tipo_pessoa":"PF",
"cpf":"",
"nome":"Jo\u00e3o",
"cnpj":null,
"ie":null,
"suframa":null,
"ramo_de_atividade":null,
"ano_de_fundacao":null,
"informacoes_adicionais":"",
"criado":"2014-12-04 08:33:48",
"modificado":"2015-02-28 14:48:40",
"status":"A",
"contatos":[
{
"id_rm_cliente":"18",
"id_rm_contato":"29",
"id_rm_empresa":"1",
"cod_id":"6ea9ab1baab9e19094440c317e21b",
"nome":"Vitto",
"cargo":null,
"criado":"2014-12-04 08:34:25",
"modificado":"2014-12-04 08:34:25",
"status":"A",
"telefones":null,
"emails":null
}
],
"telefones":[
],
"emails":[
],
"enderecos":[
{
"id_rm_endereco":"28",
"bairro":"Vilrasil",
"cep":"",
"cidade":"LAwwdo",
"complemento":"",
"endereco":"oaidow",
"estado":"Paran\u00e1",
"numero":"70",
"tipo_endereco":"Residencial",
"latitude":-22.2222,
"longitude":-51.1476,
"criado":"2014-12-04 08:34:11",
"modificado":"2015-02-28 14:48:40",
"status":"A"
}
]
}
]
}
And I have a model that to get those data and register it in my database, so I have 3 tables which is - clients, emails and clients_have_emails, and here is how I feed those tables:
if (mClienteModelRest.get(i).getEmails().size() > 0) {
for (int pEmail = 0; pEmail < mClienteModelRest.get(i).getEmails().size(); pEmail++) {
if (existeRegistro(mClienteModelRest.get(i).getEmails().get(pEmail).getId_rm_email(), tabelaEMAILS, EmailModel.Coluna.EMAILS_ID) == 0) {
EmailModel mEmailModel = new EmailModel();
mEmailModel.setId_rm(mClienteModelRest.get(i).getEmails().get(pEmail).getId_rm_email());
mEmailModel.setEmail(mClienteModelRest.get(i).getEmails().get(pEmail).getEmail());
mEmailModel.setTipo(mClienteModelRest.get(i).getEmails().get(pEmail).getTipo());
ContentValues mEmailContentValues = new ContentValues();
mEmailContentValues.put(EmailModel.Coluna.ID_RM, mEmailModel.getId_rm());
mEmailContentValues.put(EmailModel.Coluna.EMAIL, mEmailModel.getEmail());
mEmailContentValues.put(EmailModel.Coluna.TIPO, mEmailModel.getTipo());
long idEmail = bd.insert(tabelaEMAILS, "", mEmailContentValues);
int idCliente = existeRegistro(mClienteModelRest.get(i).getId(), tabelaCLIENTES, ClienteModel.Coluna.CLIENTES_ID);
/* bind email with clients */
ContentValues mClienteHasEmailContentValues = new ContentValues();
mClienteHasEmailContentValues.put(ClienteHasEmailModel.Coluna.CLIENTES_ID, idCliente);
mClienteHasEmailContentValues.put(ClienteHasEmailModel.Coluna.EMAILS_ID, idEmail);
bd.insert(tabelaCLIENTES_HAS_EMAILS, "", mClienteHasEmailContentValues);
I need a way to do the same thing with ionic, to bind the emails with the clients, what can I do to achieve that?