小编Brh*_*aka的帖子

如何使用 react-router-dom 创建动态路由?

我学习反应并知道如何创建静态路由,但无法弄清楚动态路由。也许有人可以解释一下,我将不胜感激。让有两个组件,一个用于渲染路由,另一个作为路由的模板。也许代码有问题,但希望你明白..

这是渲染路由的组件:

import React, { Component } from 'react';
import axios from 'axios';
import Hero from './Hero';

class Heroes extends Component {
  constructor(props) {
    super(props);
    this.state = {
      heroes: [],
      loading: true,
      error: false,
    };
  }
  componentDidMount() {
    axios.get('http://localhost:5555/heroes')
      .then(res => {
        const heroes = res.data;
        this.setState({ heroes, loading: false });
      })
      .catch(err => { // log request error and prevent access to undefined state
        this.setState({ loading: false, error: true });
        console.error(err);
      })
  }
  render() {
    if (this.state.loading) {
      return …
Run Code Online (Sandbox Code Playgroud)

json reactjs

12
推荐指数
3
解决办法
2万
查看次数

在 Serilog 中,如何在使用 {Properties} 格式说明符时从 JSON 格式的日志消息中删除空括号?

我有以下outputTemplate字符串:

var formatString = "{NewLine}[{Timestamp:dd-MMM-yyyy HH:mm:ss}] {Level} {SourceContext}{NewLine}{Properties:j}{NewLine}{Message:lj}{NewLine}{Exception}";
Run Code Online (Sandbox Code Playgroud)

我有几个丰富的配置来添加和删除属性。在没有要记录的属性的情况下,我一直在一行中获取空的 JSON 括号。例如,当有要记录的属性时,我会收到如下日志消息:

[05-Jul-2019 07:13:57] Information Microsoft.AspNetCore.Mvc
{ "UserName": "SomeUser" }
This is some log message with a property that was not removed by any of the enrichers.
Run Code Online (Sandbox Code Playgroud)

但是,在没有属性的情况下,我会得到这个

[05-Jul-2019 07:13:57] Information Microsoft.AspNetCore.Mvc
{}
This is some log message that contains no properties
Run Code Online (Sandbox Code Playgroud)

空的 JSON 括号{}散落在我的日志中,只是增加了噪音。如何扩展或覆盖 Serilog 以摆脱这些括号?

json serilog asp.net-core

11
推荐指数
1
解决办法
257
查看次数

函数指针中标准C++ 98中函数类型参数的静态推断

我有一个共享库,导出一元函数,如:

extern "C" void foo(int);
extern "C" void zoo(double);
Run Code Online (Sandbox Code Playgroud)

该库由没有C++ 11支持的编译器使用.我想从函数名称中在结构中静态推断函数类型.

我可以写:

template <typename T, void(*)(T)> struct A{ typedef T arg_t; };
Run Code Online (Sandbox Code Playgroud)

为此,我必须T在实例化模板时明确指定类型,即我必须编写

A<int, &foo>
Run Code Online (Sandbox Code Playgroud)

而不仅仅是

A<&foo>
Run Code Online (Sandbox Code Playgroud)

鉴于此信息嵌入在指针类型中,有没有一种方法可以静态提取?

c++ templates c++98

9
推荐指数
1
解决办法
225
查看次数

如何使用表内的 JSONB 数据类型和 PostgreSQL JDBC 驱动程序将 JSON 对象存储到 PostgreSQL 中

我想将以下 json 对象保存到 PostgreSQL db 表中作为 jsonb

{
  "fname":"john",
  "lname:"doe",
}
Run Code Online (Sandbox Code Playgroud)

我目前使用 PGObject 创建对象并将类型设置为 jsonb 并将值作为 json 字符串传递

寻找 micronaut-data 和 micronaut 的更好方法 micronaut-data 中 是否支持任何本机数据类型将 Java 对象转换为 JSON 并存储在 db 中? 如何使用 postgres jdbc 驱动程序保存数据

使用 :jsonb 在查询中进行类型转换已经尝试过使用原始 jdbc 如果它适用于 micronaut-data / 捕食者怎么做?

postgresql json jdbc kotlin micronaut

9
推荐指数
1
解决办法
2896
查看次数

PostgreSQL:查询 JSON 数组中的元素

我有一个如下所示的数据库表:

---------------------------------------
| id | json_array (jsonb)             |
---------------------------------------
|  1 | [{"a": 1}, {"a": 5}, {"a": 1}] |
|  2 | [{"a": 2}]                     |
|  3 | [{"a": 1}]                     |
---------------------------------------
Run Code Online (Sandbox Code Playgroud)

我想使用 PostgreSQL 的 JSON 查询功能来选择json_array数组中的某些子字典,例如字典 where "a": 1

输出应该是

------------------
| id | json_dict |
------------------
|  1 | {"a": 1}  |
|  1 | {"a": 1}  |
|  3 | {"a": 1}  |
------------------
Run Code Online (Sandbox Code Playgroud)

以下查询适用于每个数组中的第一个元素,但我想检查所有元素:

---------------------------------------
| id | json_array (jsonb)             |
---------------------------------------
| …
Run Code Online (Sandbox Code Playgroud)

sql postgresql json jsonb

7
推荐指数
2
解决办法
2万
查看次数

将 CSV 文件内容与 filecmp 进行比较并忽略元数据

import filecmp

comparison = filecmp.dircmp(dir_local, dir_server)
comparison.report_full_closure()
Run Code Online (Sandbox Code Playgroud)

我想将本地计算机上保存的所有 CSV 文件与服务器上保存的文件进行比较。两者的文件夹结构相同。我只想进行数据比较不是元数据(如创建时间等)。我正在使用filecmp但它似乎执行元数据比较。有没有办法做我想做的事?

python csv pandas

7
推荐指数
1
解决办法
704
查看次数

如何通过`DataTable`定义将CSS应用于&lt;table&gt;元素(使其宽度为100%)?

问题

我正在使用Dash “ v1.0”套件(请参阅下面的pip要求)。我想创建一个DataTable全角(就像一个<p>元素)。

我已将表设置如下(下面是完整的MWE):

dash_table.DataTable(
    …
    style_table={
        'maxHeight': '50ex',
        'overflowY': 'scroll',
        'width': '100%',
        'minWidth': '100%',
    },
    …
Run Code Online (Sandbox Code Playgroud)

但是,即使<div class="cell cell-1-1 dash-fixed-content">生成的HTML容器是全角的,<table>它所包含的容器也不是全角,如下面的演示所示。

gif演示

问题是... 同一个类似的代码可与短跑0.X ...

使用Dash 1.0,如何使单元格自动水平扩展,以使表格填满整个水平空间?

或者换句话说,如何<table>通过DataTable元素设置元素的样式?


最小(有时不是)工作示例

与Dash 0.x:

  • 0.x_requirements.txt
dash-core-components==0.39.0
dash-html-components==0.13.2
dash-renderer==0.15.1
dash-table==3.1.7
dash==0.31.1
datetime
pandas==0.23.4
plotly==3.4.1
Run Code Online (Sandbox Code Playgroud)
  • 0.x_testapp.py
dash-core-components==0.39.0
dash-html-components==0.13.2
dash-renderer==0.15.1
dash-table==3.1.7
dash==0.31.1
datetime
pandas==0.23.4
plotly==3.4.1
Run Code Online (Sandbox Code Playgroud)

使用Dash 1.0:

  • 1.x_requirement.txt
dash_renderer==1.0.0
dash-core-components==1.0.0
dash-html-components==1.0.0
dash-table==4.0.0
dash==1.0.0
pandas==0.24.2
plotly==3.10.0 …
Run Code Online (Sandbox Code Playgroud)

css plotly-dash

6
推荐指数
1
解决办法
450
查看次数

Sqlalchemy 包含带有 join 和 contains_eager 的空关系

我有 2 个模型 Recording 和 Recording_results 像这样

class Recording(Base):
    __tablename__ = 'recordings'

    id = Column(Integer, primary_key=True)
    filename = Column(String, nullable=False)

    language_id = Column(Integer, ForeignKey('languages.id'), nullable=False)
    language = relationship("Language", back_populates="recordings")

    user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
    user = relationship("User", back_populates="recordings")

    created_at = Column(DateTime, nullable=False, default=func.now())
    updated_at = Column(DateTime, nullable=False,
                        default=func.now(), onupdate=func.now())
    deletedd_at = Column(DateTime, nullable=True)

    def __repr__(self):
        return 'id: {}'.format(self.id)

User.recordings = relationship("Recording", order_by=Recording.id, back_populates="user")
Language.recordings = relationship("Recording", order_by=Recording.id, back_populates="language")


class RecordingResult(Base):
    __tablename__ = 'recording_results'

    id = Column(Integer, primary_key=True)
    is_with_dictionary = Column(Boolean, …
Run Code Online (Sandbox Code Playgroud)

python json sqlalchemy filter relationship

6
推荐指数
1
解决办法
1万
查看次数

rootInstance.findByType("输入"); 给出预期 1 但发现 2 个节点类型为“未定义”的实例

所以我有一个显示一些文本字段的组件。一个输入,一个选择,根据用户在该选择上使用的输入,(选择的值)显示或不显示第三个。

我尝试使用 React-Test-Renderer 仅测试第一个输入字段,但出现以下错误:预期 1 但发现 2 个节点类型为“未定义”的实例

这是输入字段代码:

    <div>
      <div className="container">
        <h3 className="h3">Info</h3>
        <div className="row">
          <div className="col">
            <label htmlFor="test">test:</label>
            <input
              id="myID"
              value={aPropThatIsAnEmptyString}
              type="text"
              className={`form-control form-control-sm ${style.fieldsGap}`}
              onChange={e => setTest(e.target.value)}
              placeholder="test"
            />
          </div>
          <div className="col">
            <label htmlFor="ddlType">test2:</label>
            <select
              id="SelectId" 
Run Code Online (Sandbox Code Playgroud)

这是我的测试代码:


 it("test input field", () => {
    const newProps = {
      something: initialState,
      dispatch: reducer
    };
    const component = TestRenderer.create(
      <ContextBR.Provider value={{ ...newProps }}>
        <ComponentWithTheFields/>
      </ContextBR.Provider>
    );
    const rootInstance = component.root;
    console.log(rootInstance);
    const inputField = rootInstance.findByType("input");

    inputField.props.onChange({ target: { value: "" …
Run Code Online (Sandbox Code Playgroud)

reactjs react-test-renderer

5
推荐指数
1
解决办法
5657
查看次数

Dialogflow 从 webhook 发送自定义有效负载 json

从 Dialogflow 控制台,我可以像这样设置自定义有效负载

在此处输入图片说明

如何从 webhook 自定义集成发送完全相同的响应。

我尝试从 Flask 将它作为 JSON 发送,但没有用。

json dialogflow-es

5
推荐指数
2
解决办法
1616
查看次数