javascript - Mapping array in Vue JS -


i'm developing small application in vuejs 2.0 i'm having data set this:

{"data":     [         {             "id":8,             "salutation":"mr",             "first_name":"madhu",             "last_name":"kela",             "number":"2343253455",             "mobile":"3252345435",             "email":"madhu@reliancemf.com",             "alt_email":null,             "address":"mumbai bkc",             "city":"mumbai",             "state":null,             "country":"india",             "profile":null,             "sectors_interested":"[\"insurance\",\"infrastructure\",\"information technology\",\"hevy machines\",\"healtcare\"]",             "companies_interested":"[4]",             "interactions_count":11,             "client_interactions_count":0,             "company":[                 {                     "id":7,                     "name":"reliance mf",                     "address":"mumbai bkc",                     "city":"mumbai",                     "state":null,                     "country":"india",                     "type":"investor",                     "sub_type":"mutual fund",                     "is_client":0,                     "pivot":{                         "contact_id":8,                         "company_id":7,                         "created_at":"2017-07-01 17:07:08",                         "updated_at":"2017-07-01 17:07:08"                     }                 }             ]         },         {             "id":7,             "salutation":"ms",             "first_name":"xyz",             "last_name":"abc",             "number":"1847171087",             "mobile":"8327523057",             "email":"skbkjgerbra@dabflvdjf.com",             "alt_email":null,             "address":"mumbai",             "city":"mumbai",             "state":null,             "country":"india",             "profile":null,             "sectors_interested":"[\"insurance\",\"information technology\",\"infrastructure\",\"hevy machines\"]",             "companies_interested":"[6,4]",             "interactions_count":8,             "client_interactions_count":0,             "company":[                 {                     "id":3,                     "name":"franklin fun",                     "address":"mumbai",                     "city":"mumbai",                     "state":null,                     "country":"india",                     "type":"investor",                     "sub_type":"mutual fund",                     "is_client":0,                     "pivot":{                         "contact_id":7,                         "company_id":3,                         "created_at":"2017-07-01 16:59:41",                         "updated_at":"2017-07-01 16:59:41"                     }                 }             ]         }     ] } 

i want map these values this:

return this.model.map(d => ({     name: d.first_name + ' ' +d.last_name,     company: d.company[0].name,     email: d.email,     mobile: d.mobile,     profile: d.profile,     count: d.interactions_count ? d.interactions_count : d.client_interactions_count })) 

also see in code want place interactions_count comparing i.e. if interactions_count 0 want map client_interactions_count, i'm unable company name first array parameter, , order count in descending order whatever comes response. me out in this. thanks.

const data = [      {          "id":8,          "salutation":"mr",          "first_name":"madhu",          "last_name":"kela",          "number":"2343253455",          "mobile":"3252345435",          "email":"madhu@reliancemf.com",          "alt_email":null,          "address":"mumbai bkc",          "city":"mumbai",          "state":null,          "country":"india",          "profile":null,          "sectors_interested":"[\"insurance\",\"infrastructure\",\"information technology\",\"hevy machines\",\"healtcare\"]",          "companies_interested":"[4]",          "interactions_count":11,          "client_interactions_count":0,          "company":[              {                  "id":7,                  "name":"reliance mf",                  "address":"mumbai bkc",                  "city":"mumbai",                  "state":null,                  "country":"india",                  "type":"investor",                  "sub_type":"mutual fund",                  "is_client":0,                  "pivot":{                      "contact_id":8,                      "company_id":7,                      "created_at":"2017-07-01 17:07:08",                      "updated_at":"2017-07-01 17:07:08"                  }              }          ]      },      {          "id":7,          "salutation":"ms",          "first_name":"xyz",          "last_name":"abc",          "number":"1847171087",          "mobile":"8327523057",          "email":"skbkjgerbra@dabflvdjf.com",          "alt_email":null,          "address":"mumbai",          "city":"mumbai",          "state":null,          "country":"india",          "profile":null,          "sectors_interested":"[\"insurance\",\"information technology\",\"infrastructure\",\"hevy machines\"]",          "companies_interested":"[6,4]",          "interactions_count":8,          "client_interactions_count":0,          "company":[              {                  "id":3,                  "name":"franklin fun",                  "address":"mumbai",                  "city":"mumbai",                  "state":null,                  "country":"india",                  "type":"investor",                  "sub_type":"mutual fund",                  "is_client":0,                  "pivot":{                      "contact_id":7,                      "company_id":3,                      "created_at":"2017-07-01 16:59:41",                      "updated_at":"2017-07-01 16:59:41"                  }              }          ]      }  ];    const result = data.map((item) => {    return {      name: item.first_name + ' ' + item.last_name,      company: item.company[0].name,      email: item.email,      mobile: item.mobile,      profile: item.profile,      count: item.interactions_count ? item.interactions_count : item.client_interactions_count    };  }).sort((a, b) => b.count - a.count);     console.log(result);


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -