我的任务是在单击提交按钮时显示 flash 消息(“成功创建”)。[单击提交按钮,数据将存储在服务器中]我已经运行了这个命令 npm i react-flash-message。
<form onSubmit={this.handleSubmit}>
<input type="submit" value="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
处理提交函数:
handleSubmit(event) {
fetch('url', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: this.state.name,
description: this.state.description
})
}).then(res => {
return res.json()
})
.then(data => console.log(data))
.then(() => {
window.location.reload(false)
/* return (
<div>
<FlashMessage duration={5000}>
<strong>I will disapper in 5 seconds!</strong>
</FlashMessage>
</div>
) */
})
/* window.flash('record has been created successfully!', 'success') */
.catch(error => console.log('ERROR from create component'))
}
}
Run Code Online (Sandbox Code Playgroud)
我已经评论了我试图显示 Flash …
我有一个数据集。它的一列 - “关键字” - 包含分类数据。我尝试使用的机器学习算法仅采用数字数据。我想将“关键字”列转换为数值 - 我该怎么做?使用自然语言处理?一袋话?
我尝试了以下但我得到了ValueError: Expected 2D array, got 1D array instead.
from sklearn.feature_extraction.text import CountVectorizer
count_vector = CountVectorizer()
dataset['Keyword'] = count_vector.fit_transform(dataset['Keyword'])
from sklearn.model_selection import train_test_split
y=dataset['C']
x=dataset(['Keyword','A','B'])
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(x_train,y_train)
Run Code Online (Sandbox Code Playgroud) 我是本机反应的新手。我想创建导航栏/可折叠下拉菜单,其中应包含主页、博客、注册、登录按钮/链接。单击该按钮时,它应该导航到相应的页面。
应用程序.js
import React from 'react';
import { Blogs } from './app/views/Blogs.js';
import {Signup } from './app/views/Signup.js;
import {Login } from './app/views/Login.js;
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { Home } from './app/views/Home.js';
const AppNavigator = createStackNavigator(
{
BlogsRT: {
screen: Blogs
},
HomeRT: {
screen: Home
},
SignupRT:{
screen: Signup
} ,
LoginRT:{
screen: Login
},
},
{
initialRouteName: 'HomeRT'
}
);
const MyRoutes = createAppContainer(AppNavigator);
export default class App extends React.Component …Run Code Online (Sandbox Code Playgroud)