javascript - 如何从谷歌 api 文档中的数据中制作 vuex getter?
问题描述
我正在尝试使用来自 google dosc api 的平面数据在 vuex 商店中制作 getter。我需要做的就是获取 textRun 内容并将其保存在数组中(因为消息很少)。现在我将这个响应硬编码为如下状态:
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
},
]
}
}
],
}
然后我做了一个吸气剂message
并map
从lodash使用:
message: (state) => {
let message = '';
map(state.googleResponse, (element) => ({
content: map(element.body.content, (content) => {
map(content.paragraph.elements, (obj) => {
message += get(obj, 'textRun', '')
})
})
}))
}
但是当我签message
入 vuex 时,它说未定义......我想拥有带有 textRun 对象的数组。问题可能出在哪里?
解决方案
我想知道您是否可以通过这种方式将消息保存在数组中?你可以这样写
let messageArray = state.googleResponse.map(
item => item.body.content.map(
itemCotent => itemCotent.paragraph.elements.map(
itemElements => itemElements.textRun.content)))
推荐阅读
- lldb - lldb 是否可以在断点检查已写入文件的内容或它生成/使用的 IPC 机制中的数据?
- sharepoint - 如何使用powershell脚本从sharepoint中的自定义列表中删除10000个项目
- python - 什么是更改大文件的有效方法
- java - Java 程序 - 使用 For 循环的插入排序
- c# - C# 表达式:数据表的 SQL/LINQ 动态排序
- angular - 通过 ngModel 将绑定值从 Input 元素传递给 Model
- javascript - 获取访问者的纬度和经度并显示它的谷歌地图
- python - 如何使用 LIKE 子句转义 pymysql 中的 % 和 \ 符号?
- mysql - 使用模糊匹配将 2 个 MySQL 表合并为一个
- python - 修复我的代码以使用禁用按钮