小编tha*_*.ts的帖子

在 Ant 设计 (antd) 表组件中使用带有自定义过滤器的 React Hooks 的 ref

我正在尝试将 Antd Table https://ant.design/components/table/与自定义过滤器和 React Hooks 一起使用。提供的示例中的大部分代码都成功转换为钩子的逻辑,但我不知道如何从代码中转换“this.searchInput”(在下面注释)。

来自 Antd 站点的示例,由我转换为 React Hooks:

import { Table, Input, Button, Space } from 'antd';
import Highlighter from 'react-highlight-words';
import { SearchOutlined } from '@ant-design/icons';



function App() {
  const [searchText, setSearchText] = useState('');
  const [searchedColumn, setSearchedColumn] = useState('');

  const data = [
    {
      key: '1',
      name: 'John Brown',
      age: 32,
      address: 'New York No. 1 Lake Park',
    },
    {
      key: '2',
      name: 'Joe Black',
      age: 42,
      address: 'London No. 1 Lake …
Run Code Online (Sandbox Code Playgroud)

reactjs antd react-hooks

9
推荐指数
2
解决办法
6405
查看次数

MongoDB - 如果不满足 arrayFilters,则对数组执行 upsert

我在 mongo 中存储了以下文件:

{
"_id" : ObjectId("5d1a08d2329a3c1374f176df"),
"associateID" : "1234567",
"associatePreferences" : [ 
    {
        "type" : "NOTIFICATION",
        "serviceCode" : "service-code",
        "eventCode" : "test-template",
        "preferences" : [ 
            "TEXT", 
            "EMAIL"
        ]
    }, 
    {
        "type" : "URGENT_NOTIFICATION",
        "serviceCode" : "service-code",
        "eventCode" : "test-template",
        "preferences" : [ 
            "TEXT"
        ]
    }
]
}
Run Code Online (Sandbox Code Playgroud)

我基本上试图根据它的类型、serviceCode 和 eventCode 查询 associatePreferences 数组的元素之一,并向首选项数组添加一个新值。但是,如果类型、serviceCode 和 eventCode 的组合不存在,我想向带有这些值的 associatePreferences 数组添加一个新元素。这是我当前的查询:

db.user_communication_preferences.update(
   {'associateID':'testassociate'}, 
   {$addToSet:{'associatePreferences.$[element].preferences':"NEW_VALUE"}}, 
   {arrayFilters:[{'element.serviceCode':'service-code-not-present', 'element.eventCode':'event-code-not-present','element.type':'URGENT_NOTIFICATION'}]}
)
Run Code Online (Sandbox Code Playgroud)

如果所有 arrayFilters 都存在于 associatePreferences 的元素中,则此查询有效,但如果不存在,则不会添加新元素。我错过了什么?

mongodb mongodb-query

8
推荐指数
1
解决办法
374
查看次数

将 react-admin 与 snowpack 一起使用

我想react-admin在一个项目中使用,snowpack但遇到以下错误

? snowpack failed to load node_modules/ra-core/node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js
  'default' is not exported by node_modules/@sheerun/mutationobserver-shim/dist/mutationobserver.min.js, imported by node_modules/ra-core/node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js
Run Code Online (Sandbox Code Playgroud)

我不确定这是一个错误react-admin还是它的依赖项之一,它可能可以通过更改配置来解决snowpack.config.json

繁殖步骤

使用Create Snowpack App初始化一个 Snowpack 项目

npx create-snowpack-app new-dir --template @snowpack/app-template-react --use-yarn
Run Code Online (Sandbox Code Playgroud)

添加包 react-admin

yarn add `react-admin`
Run Code Online (Sandbox Code Playgroud)

添加以下行 src/index.jsx

import { Admin } from 'react-admin'
Run Code Online (Sandbox Code Playgroud)

运行命令以启动应用程序

npm start
Run Code Online (Sandbox Code Playgroud)

会有一堆警告,如:

The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
Run Code Online (Sandbox Code Playgroud)
Conflicting namespaces: node_modules/ra-core/esm/i18n/index.js re-exports 'TranslationContext' from …
Run Code Online (Sandbox Code Playgroud)

javascript rollup reactjs react-admin snowpack

8
推荐指数
0
解决办法
411
查看次数

如何从 M2 降级到 M0 mongoDB Cluster Tier

我有 M2 Mongodb 集群,想降级到 M0。当我去修改它只允许升级。还有其他方法可以降级到免费套餐吗?

mongodb-atlas

4
推荐指数
1
解决办法
891
查看次数

在react-hook-form中react-table v7

我正在研究一个复杂的反应形式,它几乎没有受控输入以及网格/表格。目前我正在使用react-hook-form进行验证。
这是我的模型。这里的想法是根据需要显示网格,直到用户添加一些数据。用户可以通过单击“+”或“-”按钮添加/删除数据。

小样
当我在这里提交时,我在提交的数据中看到的是

{
  "fname": "sasa",
  "lname": "asasasa"
} 
Run Code Online (Sandbox Code Playgroud)

这是预期的输出

{
  "fname": "sasa",
  "lname": "asasasa",
  "localAddress":[
    {
      "street1":"street1",
      "street2":"street2",
      "city":"city"
    },
    {
      "street1":"street2",
      "street2":"street2",
      "city":"city"
    }
  ]
} 
Run Code Online (Sandbox Code Playgroud)



这是我的codesanbox
Codesanbox

不知道如何将react-table(或任何表组件)与react-hook-form(或任何react形式)集成。使用“react-table”构建表单对我来说是必须的。

感谢任何帮助。

reactjs react-table react-hook-form react-forms

3
推荐指数
1
解决办法
8368
查看次数

带有 VPC 无服务器连接器出口的 Google Cloud Functions 与 Cloud NAT 不工作

这与以下问题有关,这些问题已过时

目前 GCP 具有 VPC Serverless Connector,它允许您通过 VPC 连接器路由所有流量并设置 Cloud NAT 以获取静态 IP 地址。

我遵循以下指南https://cloud.google.com/functions/docs/networking/network-settings#associate-static-ip使用该区域,us-east4但来自我的云功能的外部请求总是超时。

我不确定这是一个错误还是我错过了一些东西。

编辑:为了确保我已遵循所有步骤,我gcloud尽可能使用, 命令执行所有步骤。这些命令是从 GCP 的指南中复制而来的。

  1. 设置项目 ID 以备将来使用
PROJECT_ID=my-test-gcf-vpc-nat
Run Code Online (Sandbox Code Playgroud)
  1. 转到控制台并启用计费

  2. 设置 VPC 和测试虚拟机以测试 Cloud NAT

gcloud services enable compute.googleapis.com \
  --project $PROJECT_ID

gcloud compute networks create custom-network1 \
  --subnet-mode custom \
  --project $PROJECT_ID

gcloud compute networks subnets create subnet-us-east-192 \
  --network custom-network1 \
  --region us-east4 \
  --range 192.168.1.0/24 …
Run Code Online (Sandbox Code Playgroud)

google-cloud-platform google-cloud-functions google-cloud-networking

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

Mongodb 聚合以对数组中最常见的项目进行排序?

集合中的项目包含一个字符串数组。我想查找数组中最匹配元素的项目并对其进行排序。

考虑一个集合:

[
    {
        "item_name":"Item_1",
        "tags":["A","B","C","D","E"]
    },
    {
        "item_name":"Item_2",
        "tags":["A","B","D","E","G"]
    },
    {
        "item_name":"Item_3",
        "tags":["B","C","E","H"]
    }

]
Run Code Online (Sandbox Code Playgroud)

我想基于像 ["B","D","G","F"] 这样的数组对集合进行排序,它将返回

[

    {
        "item_name":"Item_2",
        "tags":["A","B","D","E","G"]
    },
    {
        "item_name":"Item_1",
        "tags":["A","B","C","D","E"]
    },
    {
        "item_name":"Item_3",
        "tags":["B","C","E","H"]
    }

]
Run Code Online (Sandbox Code Playgroud)

预期的顺序将是 Item_2、Item_1,然后是 Item_3,因为,

  • Item_2 匹配 3 个项目(“B”、“D”和“G”)
  • 然后 Item_1 有 2 个匹配项(“B”和“D”)
  • 最后 Item_3 有 1 场比赛(“B”)

如果不在 mongodb 中,JavaScript 方法也将受到赞赏

javascript mongoose mongodb mongodb-query aggregation-framework

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