I'm looking to create a Vuex getter to retrieve data from the Google API documentation – can you help

Can someone help me figure out how to create a getter in Vuex store with flat data from the Google Docs API? My goal is to extract the textRun content and store it in an array because there will be multiple messages. Currently, I have hard coded this response in the state like this:

 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
            },
          ]
        }
      }
    ],
} 

After that, I created a getter message and used the map function 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', '')
      })
    })
  }))
}

However, when I check the message in Vuex, it shows as undefined. I want to have an array with textRun objects. What could be causing this issue?

Answer №1

Is it possible to store the message in an Array using this method? Feel free to structure your code like this:

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

Answer №2

Make sure to include the message variable in your getter method.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ajax is functional, however the server is not responding

After many attempts to resolve the issue with my website, I am turning to this community in hopes of finding a solution. The problem lies in the fact that while the ajax success function appears to be working and shows a status code of 200 in the network ...

What is the proper way to utilize setTimeout in TypeScript?

Let's take a look at an example of how to use setTimeout in Angular and TypeScript: let timer: number = setTimeout(() => { }, 2000); However, upon compilation, you may encounter the following error message: Error TS2322: Type 'Timeout' ...

Steps for programmatically closing a Dialog Window in a showmodeldialog window

When opening the window, I follow this approach: var MyArgs = new Array(ParmA, ParmB, ParmC, ParmD, ParmE, ParmF); var leftpost = getWindow_TotalWidth() - 1000 - 100; var WinSettings1 = "dialogHeight:580px; dialogWidth:950px;edge:Raised; center:Yes; resi ...

What is the best way to create a button that can cycle through various divs?

Suppose I want to create a scroll button that can navigate through multiple div elements. Here is an example code snippet: <div id="1"></div> <div id="2"></div> <div id="3"></div> <div id="4"></div> <div ...

Several jquery libraries are experiencing malfunctions

<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(".slidingDiv").hide(); $(".show_hide").show().click ...

The issue of jQuery, Ajax, and MVC6 parameters becoming null after an Ajax request has been identified

Hello everyone, I am a beginner in asp.net core, c# and MVC 6. Currently, I am facing an issue with sending data over ajax to my controller. function sendAjaxData() { $.ajax({ url: "AjaxWithData", // using hardcoded value for testing purpose type ...

Failure when running npm start command in Nest js

After setting up a fresh Nest js on a new EC2 machine, I encountered an error when trying to run it for the first time. The error message indicated that the npm install process failed abruptly without any visible error: ubuntu@ip-172-31-15-190:~/projects/m ...

Provide a TypeScript interface that dynamically adjusts according to the inputs of the function

Here is a TypeScript interface that I am working with: interface MyInterface { property1?: string; property2?: string; }; type InterfaceKey = keyof MyInterface; The following code snippet demonstrates how an object is created based on the MyInter ...

Using AngularJS client and Flask server for a RESTful call, one can include the

I am currently facing an issue where I need to send a REST request from my AngularJs client to a Flask server. The problem arises when one of the ids (key) in the request contains a forward slash. Interestingly, if the key does not contain a slash, the re ...

Clear the Material-UI textfield upon form submission

After submitting the form, how can I clear the value from the TextField? All of the components in my code are functional components, not class ones. The example below shows one of the TextFields, with others similar to it. Currently, setting type='sea ...

Having trouble with a beginner problem that's hindering the functionality of my code

I have been struggling with a particular piece of code and it is driving me crazy as I am unable to locate the source of my error: $.post($form.attr('action'), $form.serialize(), function (result) { console.log(result); if (result.succes ...

What is the best way to incorporate an ID from a scala template into an AJAX request?

In my application built on the Play Framework 2.3.8, users can input questions and answers. The view class receives a List[Question] which is iterated through using a for each loop to display them: @for(question <- questionList){ <!-- Questions --& ...

Tips for ensuring session token verification remains intact upon reloading

I am currently in the process of developing a website using the Next.js framework and I am seeking advice on how to prevent the reload effect that occurs when transitioning from the login page back to the main page for just a fraction of a second. Below i ...

I have created an Express.js application. Whenever I visit a page, I consistently need to refresh in order for the variables to appear correctly

Hello, I'm seeking some assistance. Despite my efforts in searching for a solution, I have not been successful in finding one. I've developed an application using Express.js that includes a basic form in jade. The intention is to display "Yes" i ...

Trouble with executing AJAX for API call

My current project is built on CI3 and I have created an API that belongs to a different domain than the application itself. $.ajax({ url: "http://www.example.com/restapi/index.php/api/user", type: "GET", data: {"user_id": user_id} ...

Define variables using specific class components only

Consider a scenario where we define a class as follows: class House { street: string; pools: number; helicopterLandingPlace: boolean; } Now, I have created a service to update my house. putHouse(house: House) { // some put request } How ...

"Enhance your website with the magic of jQuery magnific-popup

Is there a way to add an additional button to the jquery magnific-popup component that can close the dialog box? I am currently utilizing this component to insert descriptions for photos, so I need a submit button that will successfully add the descriptio ...

Implementing a Laravel Many-To-Many relationship with various functionalities

After feeling confident in my Laravel skills, I hit a roadblock that I can't seem to find the solution for online. My project involves using Laravel and Vue to store products with ingredients. The products are kept in a separate table, while the ingre ...

Employing various Class Methods based on the chosen target compiler option

Is there a way to instruct TypeScript to utilize different implementations of methods within the same class, based on the specified target option in the tsconfig.json file? I am currently transitioning one of my scripts to TypeScript to streamline managem ...

Publishing Your App on the Android Market with PhoneGap

Seeking a comprehensive PhoneGap tutorial that covers app publishing, especially struggling with successful app deployment. Currently experienced in HTML, CSS, and JavaScript. Any tips or advice would be greatly appreciated, thank you! I have a good gras ...