小编TRI*_*EMS的帖子

我必须遍历多级 JSON 并删除某些键

我有一个如下所示的 JSON。我需要删除 array = ["field", "type", "input"] 中提到的一些键

const result = {
   "condition":"AND",
   "rules":[
      {
         "id":"search_across",
         "operator":"equal",
         "value":1
      },
      {
         "condition":"AND",
         "rules":[
            {
               "id":"Recipe ID",
               "field":"Recipe ID",
               "type":"string",
               "input":"text",
               "operator":"equal",
               "value":"100"
            },
            {
               "condition":"AND",
               "rules":[
                  {
                     "id":"Recipe ID",
                     "field":"Recipe ID",
                     "type":"string",
                     "input":"text",
                     "operator":"equal",
                     "value":"200"
                  }
               ]
            }
         ]
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

我需要删除第 n 层的钥匙。我只能从第一级删除它(如 JSON 中所示)

javascript arrays traversal

2
推荐指数
1
解决办法
1434
查看次数

使用 Node.js 使用数据库值生成动态 word 文档

我正在尝试使用npm docx. 我正在尝试从 SQLite 数据库中读取数据,但由于异步节点 js 属性,这些值没有进入变量并显示undefined. 如果我使函数同步npm docx则会引发错误并且不会填充文档。

包.json

{
  "name": "demoName",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "docx": "^5.1.1",
    "express": "^4.17.1",
    "md5": "^2.2.1",
    "sqlite3": "^4.2.0"
  }
}
Run Code Online (Sandbox Code Playgroud)

索引.js

const docx = require('docx');
var express = require('express');
var app = express();
var db = require("./database.js")

var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: …
Run Code Online (Sandbox Code Playgroud)

javascript sqlite docx node.js express

2
推荐指数
1
解决办法
2304
查看次数

标签 统计

javascript ×2

arrays ×1

docx ×1

express ×1

node.js ×1

sqlite ×1

traversal ×1