RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-263215

Александр's questions

Martin Hope
Александр
Asked: 2020-07-22 22:58:23 +0000 UTC

如何检查按钮处理程序 React.js TypeScript 的类型

  • 0

组件有一个按钮,点击时会发生onClick事件并调用this.renderFormsSteps()方法;

一切都很好,但编译器发誓

Type 'void' is not assignable to type '((event: MouseEvent<HTMLButtonElement, MouseEvent>) => void) | undefined'

简单地说,我不知道如何设置处理程序类型并检查它们......

这是组件代码:

    interface RegistrationProps {
    login: LoginState 
}

interface RegistrationState {
    login: string, 
    name: string, 
    lastName: string, 
    activeStep: number,
}

export class Registration extends React.Component<RegistrationProps, RegistrationState> {
    constructor(props: any) {
        super(props)
        this.state = {
            login: '',
            name: '',
            lastName: '',
            activeStep: 1
        }
    }

    private renderSteps = (step: number) => {
        const classNameStep1 = step === 1 ? "activeStep" : "step";
        const classNameStep2 = step === 2 ? "activeStep" : "step";
        const classNameStep3 = step === 3 ? "activeStep" : "step";

        return (
            <React.Fragment>
            <div className={classNameStep1}>Логин и имя</div>
            <div className={classNameStep2}>Персональные данные</div>
            <div className={classNameStep3}>Пароль</div>
            </React.Fragment>
        )
    }

    private renderFormsSteps = (step: number) => {
       if (step === 1) {
           return (
               <div>
                   <div>Логин и имя</div>
                   <div><button onClick={this.handleNextStepButton(step)} type="button" className="btn btn-dark">Next</button></div> 
               </div>
           );
       } else if (step === 2) {
           return (
               <div>Персональные данные</div>
           );
       } else if(step === 3) {
           return (
               <div>Пароль</div>
           );
       } else {
           return (
               <div>...</div>
           );
       }
    }

    private handleNextStepButton = (nextStep: number)  => {
        this.setState({activeStep: nextStep});
    }

    public render() {
        const {activeStep} = this.state;
        return (
            <Container>
            <div className="registrationHead">
                <Link to="/"> Вернуться </Link>
            </div>
            <div className="registrationTitle">Регистрация</div>
            {this.renderSteps(activeStep)}
            {this.renderFormsSteps(activeStep)}
            </Container>
        );
    }
}

Если что (зависимости):

"@types/react": "^16.8.23",
"@types/react-dom": "^16.8.4",
 "typescript": "^3.5.3"
reactjs
  • 1 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-06-28 14:36:50 +0000 UTC

React-router BrowserRouter 和 HashRouter 有什么区别?

  • 2

BrowserRouter和HashRouter有什么区别?在什么情况下使用一个或这个选项更好?

reactjs
  • 1 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-02-19 20:36:31 +0000 UTC

安装 React 时出错

  • 0

我执行命令

npx create-react-app my-app cd my-app npm start

我收到这样的错误。尝试了所有步骤 - 不起作用。告诉我这个 .env 文件是什么以及它在哪里。

如何治愈?

在此处输入图像描述

reactjs
  • 1 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-10-24 03:23:42 +0000 UTC

ng-include AngularJS 不工作

  • 0

安装了xampp。我正在用 AngularJS 开发一个项目。我想将页面的一部分放在单独的文件中(导航菜单)。我使用 ng-include 指令来实现。第一次一切正常,然后,例如,如果我从以下位置删除联系人:根本没有.. 为什么?

<!doctype html>
<html  ng-app="mainPageApp">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link rel="stylesheet" href="css/style.css">
<title>...</title>
</head>
<body>
<ng-include src="'headMenu.html'"></ng-include>
</body>
</html>
javascript
  • 1 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-10-03 17:18:04 +0000 UTC

为什么不能在 C# 中添加字节 + 字节?

  • 5

我知道您需要执行类型转换,但我想了解其中的机制。
为什么这段代码会抛出错误?

byte a = 2;

byte b = a + 2; // ошибка
c#
  • 1 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-09-27 21:57:54 +0000 UTC

ABAP中如何求2个矩形相交部分的面积?

  • 1

大家下午好!有这样一个问题,需要用ABAP语言编写解决方案:

在平面上给出了两个矩形。每个矩形由两个相对顶点的坐标定义。求这些矩形的交集面积。评论。矩形的边平行于坐标轴。

规格 输入 第一行包含四个数字 - 第一个矩形的两个相对顶点的坐标。第二行包含四个数字——第二个矩形的两个相对顶点的坐标。矩形可以退化为线段甚至点。所有坐标都是从 0 到 40,000 的整数。

告诉我思考的方向以及如何解决这个问题?ABAP完全没有经验。

你觉得这个任务的难度有多高?

为什么创建 ABAP 标签不起作用,而这个论坛上还没有人创建它?难道它真的是一种很少有人对它感兴趣的语言吗?

java
  • 3 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-09-04 03:48:24 +0000 UTC

如何检查用户是否在输入中输入了空格字符?

  • 1

大家好。我正在表单中进行用户输入验证。如您所知,条件之一是该行不应包含空格,因为空字段似乎是不必要的。我想做一个这样的功能:

function checkInput (text_from_input) {
   return true ore false

}

如果该条目将完全由空格组成,则该函数将返回 false 并且该字段将不会通过检查,并且我会将所有内容都涂成红色。但我不知道在函数体中写什么。告诉我如何检查输入的空格并在这种情况下显示 false。

javascript
  • 4 个回答
  • 10 Views
Martin Hope
Александр
Asked: 2020-08-29 16:18:47 +0000 UTC

jQuery 和 CSS 样式在添加到表格时会崩溃。

  • 1

下午好。有一个用于处理表格的 DataTables 插件。

这是帕拉金网站https://www.datatables.net/。

我将它安装在我的网站上,并且桌子开始工作。

表是通过table_of_goods()函数在JS文件中创建的;

表格数据显示在以下列中: Product 1, Price 使用从 test[] 数组中获取信息的循环;

最初,我在数组test[1, 2, 3]中写了以下值;并且这些值显示在 Product 字段中。一切正常。

当我从表单向数组添加值时,一切都停止工作。样式和 jQuery 立即被禁用。同时,所有内容都添加了,但没有样式和小工具,例如 palagin 添加的表格搜索。告诉我,有什么问题?以下是该文件的 HTML 和 JS 代码。

<!DOCTYPE html>
<html lang="en">
<title>Goods</title>
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.css">

     <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script type="text/javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>


    <style>
    .bloc {background-color: #ffffff; padding: 20px;}
    .head_add {text-align: right;}
    .tab {margin-top: 50px;}
    </style>
  </head>
  <body>

   <div class="container bloc">
  <div class="row">
    <!-- 1 -->
    <div class="col-sm-6 col-md-6 col-lg-6">
    <form class="form-inline">
  <label class="sr-only" for="inlineFormInput">Name</label>

  <input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0"  id="inlineFormInput" placeholder="What are you looking for ?">


  <button type="submit" class="btn btn-primary">Search</button>
</form></div>
    <div class="col-sm-6 col-md-6 col-lg-6 head_add"><button type="button" class="btn btn-primary">Add New</button></div>
    <div class="col-sm-12 col-md-12 col-lg-12 tab">
  <div id="table"></div>
 </div>

  <div class="col-sm-12 col-md-12 col-lg-12 tab">

  <form id="add_form" class="form-inline" onsubmit="return table_of_goods()">

  <input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0"  id="good" placeholder="Good">
  <input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0"  id="inlineFormInput" placeholder="Count">
    <input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0"  id="price" placeholder="Price">

  <input id="add_update" class="btn btn-primary" type="submit" value="Add">
</form>
  </div>
  </div>
</div>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>

main.js

var test = [1,2,3];


function table_of_goods () {
    var good = '';
    var price;
    good = document.getElementById("good").value;
    var check = good.length;
    price = document.getElementById("price").value;

if (check > 0) {
    test.push([[good],[price]]);
    };


var elem = document.getElementById('table');

var table = '<table id=main_table class=display cellspacing=0 width=100%><thead><tr><th>Name</th><th>Price, $</th><th>Actions</th></tr><tfoot><tr><th>Name</th><th>Price</th><th>Actions</th></tfoot><tbody>';


for (var i = 0; i < test.length; i++){
table += '<tr><td>' + test[i] + '</td><td>495</td><td>Действия</td></tr>';
}


table += '</tbody></table>';

el.value = '';

el2.value = '';

el3.value = 'Add';

$(document).ready(function() {
    $('#main_table').DataTable();
} );

elem.innerHTML = table;

return false;
}

table_of_goods();
javascript
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5