RobDee
RobDee

Reputation: 126

How to make vuex getter from data from google api docs?

I'm trying to make getter in vuex store with flat data from google dosc api. All what I need is to take textRun content and keep this in array (because there will be few messages). Now I hardcoded this response in state like:

 state: {
    googleResponse: [
      {
        "body": {
          "content": [
            {
              "endIndex": 75,
              "paragraph": {
                "elements": [
                  {
                    "endIndex": 75,
                    "startIndex": 1,
                    "textRun": {
                      "content": "This is an ordinary paragraph. It is the first paragraph of the document",
                      "textStyle": {}
                    }
                  }
                ],
                "paragraphStyle": {
                  "direction": "LEFT_TO_RIGHT",
                  "namedStyleType": "NORMAL_TEXT"
                }
              },
              "startIndex": 1
            },
            {
              "endIndex": 102,
              "paragraph": {
                "elements": [
                  {
                    "endIndex": 102,
                    "startIndex": 75,
                    "textRun": {
                      "content": "Here's a level one heading",
                      "textStyle": {}
                    }
                  }
                ],
                "paragraphStyle": {
                  "direction": "LEFT_TO_RIGHT",
                  "headingId": "h.o1fkftgl5zwf",
                  "namedStyleType": "HEADING_1"
                }
              },
              "startIndex": 75
            },
          ]
        }
      }
    ],
} 

and after that I make a getter message and used map from lodash:

message: (state) => {
  let message = '';
  map(state.googleResponse, (element) => ({
    content: map(element.body.content, (content) => {
      map(content.paragraph.elements, (obj) => {
        message += get(obj, 'textRun', '')
      })
    })
  }))
}

But when I'm checking message in vuex it says is undefined... I want to have array with textRun objects. Where might be the problem ?

Upvotes: 0

Views: 125

Answers (2)

bin liu
bin liu

Reputation: 227

i am wondering whether you can get the message keep in Array by this way? you can write like this may your want

   let messageArray = state.googleResponse.map(
        item => item.body.content.map(
            itemCotent => itemCotent.paragraph.elements.map(
                itemElements => itemElements.textRun.content)))

Upvotes: 2

Franck Abgrall
Franck Abgrall

Reputation: 141

You need to return themessage variable in your getter.

Upvotes: 1

Related Questions