连接字符串中的字段

时间:2018-07-10 13:39:27

标签: javascript node.js string return concatenation

我创建了一个API,我希望将所有字段归还在一起,我试图将它们串联起来,但是它并没有给我字符串形式的结果。

export async function getByContaBancariaEmpresarialDescricao() {
  const resource = await Resource.query()
    .select('descricao', 'agencia', 'digito_agencia', 'conta', 
'digito_conta', 'ibi.codigo as bancoCodigo', 'ibi.numero as 
bancoNumero', 'ibi.banco as bancoNome', 'ibi.IMAGEM_LOGO as 
bancoICONE',
    ('descricao as ContaBancariaEmpresarialDescricao'),
    (`descricao`, '+', `conta`, '+', `ibi.numero`)
  )

    .joinRelation('banco', { alias: 'ibi' });


  return resource;
}

它返回此:

{
        "descricao": "BANCO TRIBANCO",
        "agencia": "1111",
        "digitoAgencia": "1",
        "conta": "1111",
        "digitoConta": "1",
        "bancoCodigo": 11,
        "bancoNumero": "111",
        "bancoNome": "BANCO TRIANGULO S/A",
        "bancoICONE": null,
        "ContaBancariaEmpresarialDescricao": "BANCO TRIBANCO",
        "numero": "111"
},

是否有一种方法可以在单个字符串中同时获得“ descricao + conta + bancoNumero”的回报?

2 个答案:

答案 0 :(得分:0)

在此df.mask(df<0,0) Out[349]: b_1 b_2 b_3 b_4 0 0.0 0.0 0.0 0.0 1 0.0 0.0 1.0 0.0 2 3.0 0.0 0.0 0.0 3 0.0 0.0 0.0 0.0 4 0.0 0.0 0.0 2.0 语句之前,请执行以下操作以获取注释中提到的预期结果:

return resource;

答案 1 :(得分:0)

这是JSON,您可以将其解析为JavaScript Object并连接字段,如下所示:

var obj = JSON.parse('{"descricao": "BANCO TRIBANCO","agencia": "1111","digitoAgencia": "1","conta": "1111","digitoConta": "1","bancoCodigo": 11,"bancoNumero": "111","bancoNome": "BANCO TRIANGULO S/A", "bancoICONE": null,"ContaBancariaEmpresarialDescricao": "BANCO TRIBANCO","numero": "111"}');

var result = obj.descricao +' ' + ' '+obj.conta + ' ' +obj.bancoNumero;