小编Rev*_*ddh的帖子

使用 nestjs 中的类验证器验证可选参数?

我想对请求有效负载应用验证,例如有字符串类型的字段名称。但名称不是必填字段,但如果存在,则必须执行@IsNotEmpty()

我试过这样的事情 @IsNotEmpty() name?: string//它不考虑?可选约束

javascript validation node.js class-validator nestjs

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

在react和redux中自动保存表单字段

我有一个父组件,它是一个表单,它通过redux连接到商店:

// FormComponent
export default connect(mapStateToProps, mapDispatchToProps)(FormComponent);
Run Code Online (Sandbox Code Playgroud)

在该表单中,我有一个输入属性列表,它是表单的子组件:

  • 表单组件
    • 名字组件
    • 姓氏组件
    • 地址组件

我需要通过在输入失去焦点时传递包含所有属性的JSON对象来进行更新API调用,从而将任何字段中的更改保存到服务器.

API调用将是这样的:

updatePersonInfo({firstname: 'new name', lastname: 'new name', address: 'new address' });
Run Code Online (Sandbox Code Playgroud)

我的想法是将PersonInfo对象作为道具从Form组件传递给所有子组件.每个子组件将从PersonInfoprops 更新一个属性,并使用更新的PersonInfo对象调度UPDATE_PERSONINFO操作.但要做到这一点,我还需要将所有子组件连接到存储:

// FirstNameComponent
export default connect(mapStateToProps, mapDispatchToProps(FirstNameComponent);

// LastNameComponent
export default connect(mapStateToProps, mapDispatchToProps)(LastNameComponent);

// AddressComponent
export default connect(mapStateToProps, mapDispatchToProps)(AddressComponent);
Run Code Online (Sandbox Code Playgroud)

但我认为我们应该避免因为性能原因而使用connect.另外,我不相信我需要4个连接器来调用一个动作.

什么是处理这种情况的最佳选择?

reactjs react-redux

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

单击链接滚动到特定部分 react.js

我已经实现了一个侧边菜单,每个部分都有一个链接标签,但我不确定在点击它们时如何实现该功能,用户被带到特定部分。我知道如果它在同一个组件中并且我以正常方式生成部分但我以不同的方式做它并且我不确定如何实现诸如 react-scroll 或 scrollchor 之类的东西。

在这里,我通过映射另一个文件中的一些数据来使用 buildTree 生成部分。

export default class CheckboxGroup extends PureComponent {
  constructor(props) {
    super(props);
    this.checkboxState = new Map();
    this.state = {
      checkboxState: new Map(),
    };
  }

  static propTypes = {
    data: PropTypes.any.isRequired,
    onChange: PropTypes.func.isRequired,
    counter: PropTypes.number,
  };

  treeCheckboxOnChange = (parentLabel, id, checked) => {
    this.checkboxState = this.checkboxState.setIn([parentLabel, id], checked);
    this.setState({
      checkboxState: this.checkboxState,
    });
  };

  mapParents = (counter, child) => {
    const parentLabel = child.get('label');
    return (
      <li key={child.get('name')} className='field'>
      <SegmentHeader style={segmentStyle} title={child.get('label')} icon={child.get('icon')}>
        <div className='fields' style={zeroMargin}> …
Run Code Online (Sandbox Code Playgroud)

javascript routes reactjs react-router

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

如何禁用 React Native 中的警告?

我知道警告很重要。但出于特定原因,我不希望它们出现在屏幕上。如何禁用出现的黄色警告screen

warnings react-native

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

如何在 React Native 中将另一个文件的视图包含到组件中?

我有以下课程如何在php中包含另一个文件(如include())中的视图。

class A extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>A</Text> 
      </View>
    );
  }
}

class B extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>B</Text>
      </View>
    );
  }
}

class C extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>B</Text>    
      </View>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我必须包含来自外部文件的视图。我们可以通过导入将一个类包含到另一个类中,但是视图呢?

import class view include react-native

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