0

I have JSON data that have two different arrays in one sheet. I want to show each Organization Page then each page have every comment from the user who selects comment this organization.

{
ListOrg: {
id: 1613,
name_org: "US company",
rating: 0,
},
Review: [
{
review_id: 3,
org_id: 1613,
user_id: 2,
description: "Very good",
rating: 3,
user: {
id: 2,
  name: "Kunjanaphorn",
  firstname: "Kunjanaphorn",
  lastname: "Boonmak",
  admin: 0,
  email: "[email protected]",
}
},
{
review_id: 4,
org_id: 1613,
user_id: 3,
description: "Not bad",
rating: 5,
user: {
  id: 3,
  name: "Kan",
  firstname: "Kan",
  lastname: "Tippayamontree",
  admin: 0,
  email: "[email protected]",
}
}
]
}

But I cannot map it to data in vue.js. I try this solution then it not work.

  data() {
    return {
      Listorgs: [],
      Reviews: [],
      Listorg: {
        name_org: "",
        picture: "",
        headerpic: "",
        description: ""
      }

  mounted() {
    axios.get("/api/listorgs/" + this.id).then(response => {
      var listorg = response.data;
      this.Reviews = listorg.Review;
      this.Listorgs = listorg.Listorg;
    });
  }

Can you tell me about syntax

I want some attribute in each array -> name_org(string) from array ListOrg, description(string) from array Review, name(string) and firstname(string) from user array in Review array for show in vue page

enter image description here

9
  • What kind of results are you getting now and what kind or result are you expecting? Commented Mar 28, 2019 at 4:41
  • I want some attribute in each array -> name_org(string) from array ListOrg, description(string) from array Review, name(string) and firstname(string) from user array in Review array Commented Mar 28, 2019 at 4:44
  • Please add your template. I guess, you can add it with v-for directive. Display fields which you need to show. Commented Mar 28, 2019 at 5:30
  • @varit05 I tray to check with console.log(ListOrgs.length); but it shows 0 Commented Mar 28, 2019 at 5:47
  • ListOrgs is object and object doesn't have length property. Which fields you want to display in the UI? Commented Mar 28, 2019 at 5:49

1 Answer 1

1

I have helped you changed a little bit and made it work, check it out.

https://jsfiddle.net/fLvy3am9/

  var listorg = response.data;
  this.orgData = listorg.ListOrg;
  this.reviews = listorg.Review.map((review) => {
    return {
      name_org: listorg.ListOrg.name_org,
      description: review.description,
      user: review.user
  };
  });

Ask me if there's any question.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works but if I get JSON data with Axios. Can you tell me about syntax when getting response.data
Usually I would use .then({ data } => to destructure the data attribute from response. Then access ListOrg using data.ListOrg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.