2017-10-02 6 views
1

私はそのようなことをしようとしています。router.getに空の配列を作成するには?

{ 
    suggestions: [{ 
     "nameClient": "John", 
     "nameFantasyClient": "smachs" 
    }, { 
     "nameClient": "José", 
     "nameFantasyClient": "apoch" 
    }] 
} 

空の配列を作成する方法については何も見つかりません。これは私のapi/product/sell/client-nameの検索に受け取った返品です。

[ 
    { 
     "nameClient": "John", 
     "nameFantasyClient": "smachs" 
    }, 
    { 
     "nameClient": "José", 
     "nameFantasyClient": "apoch" 
    } 
] 

私のrouter.getは、データベースからデータを抽出してフロントエンドに送信します。

router.get('/product/sell/name-of-client-search', function (req, res) { 
    connection.query('SELECT nameClient,nameFantasyClient FROM new_client', 
    function (err, nameOfClientToSell, fields) { 
     if (err) { 
     throw err; 
     } 
     res.send(nameOfClientToSell); 
    } 
); 
}); 

ありがとうございます!

答えて

0

オンザフライでjsonを構築できます。

router.get('/product/sell/name-of-client-search', function (req, res) { 
    connection.query('SELECT nameClient,nameFantasyClient FROM new_client', 
    function (err, nameOfClientToSell, fields) { 
     if (err) { 
     throw err; 
     } 
     res.send({ suggestions: nameOfClientToSell }); 
    } 
); 
}); 
+0

Working、Thanks; D – Gabriel

関連する問題