javascript - Pass objects in array into inquirer list choices -


i have simple node.js application search spotify api songs. because there songs same names different artist, want user able select track desired list using inquirer package.

the methods below add data search results object, , push them array. pass array inquirer prompt, user can select item.

when selected, need able of data trackdata object, whichever selection user made.

if there's better way of doing please let me know. s.o.

           let trackfetcher = new promise((resolve, reject) => {                 for(let track of data.tracks.items)                 {                     var trackdata = {                         name: track.name,                         album: track.album.name,                         artist: track.artists[0].name,                         url: track.external_urls.spotify,                     }                      tracks.push(trackdata);                     resolve(tracks);                 }             });              trackfetcher.then((tracks) => {                 inquirer.prompt([                     {                       type: 'list',                       message: 'select track list',                       choices: tracks,                       name: "track"                   }]).then(function(selected) {                      //do stuff result                 });             }); 

array of objects should contain objects 2 keys: name , value name message display , value object selected.

fixed changing object to:

                    var trackdata = {                         name : track.name + " by: " + track.artists[0].name,                         value : {                             name: track.name,                             album: track.album.name,                             artist: track.artists[0].name,                             url: track.external_urls.spotify,                         }                     } 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -