当前位置: 首页 > news >正文

自己做网站不想买空间 自己电脑可以做服务器吗?宁波小程序开发

自己做网站不想买空间 自己电脑可以做服务器吗?,宁波小程序开发,适合推广的网站有哪些,金融企业网站整站源码react 事件处理在使用React渲染RESTful服务后#xff0c;我们创建了简单的UI#xff0c;用于渲染从RESTful服务获取的员工列表。 作为本文的一部分#xff0c;我们将扩展同一应用程序以支持添加和删除员工操作。 我们将通过添加/删除员工操作来更新react-app后端api#x… react 事件处理 在使用React渲染RESTful服务后我们创建了简单的UI用于渲染从RESTful服务获取的员工列表。 作为本文的一部分我们将扩展同一应用程序以支持添加和删除员工操作。 我们将通过添加/删除员工操作来更新react-app后端api并修改现有的get employee方法以返回员工列表方法如下 步骤1.定义由PostMapping“ / employee / add”标记的addEmployee方法该方法将在类级别的员工列表中添加员工 PostMapping(/employee/add) public ListEmployee addEmployee(final RequestBody Employee employee) {System.out.println(Adding employee with name : employee.getName());if(employee.getName() ! null employee.getName().length() 0)employeeList.add(new Employee(employeeList.size(), employee.getName(), IT));return employeeList; } 步骤2.定义由PostMapping“ / employee / delete”标记的deleteEmployee方法 该方法将从与雇员姓名匹配的类级别雇员列表中删除雇员如下所示 PostMapping(/employee/delete) public ListEmployee deleteEmployee(final RequestBody Employee employee) {System.out.println(Deleting employee with name : employee.getName());final OptionalEmployee optional employeeList.stream().filter(e - e.getName().equalsIgnoreCase(employee.getName())).findAny();if(optional.isPresent()){employeeList.remove(optional.get());}return employeeList; } 最终 ReactAppApplication.java应该看起来像 SpringBootApplication RestController public class ReactAppApplication {final ListEmployee employeeList new ArrayList();public static void main(String[] args) {SpringApplication.run(ReactAppApplication.class, args);}GetMapping(/employee/get)public ListEmployee get() {return employeeList;}PostMapping(/employee/add)public ListEmployee add(final RequestBody Employee employee) {System.out.println(Adding employee with name : employee.getName());if(employee.getName() ! null employee.getName().length() 0)employeeList.add(new Employee(employeeList.size(), employee.getName(), IT));return employeeList;}PostMapping(/employee/delete)public ListEmployee delete(final RequestBody Employee employee) {System.out.println(Deleting employee with name : employee.getName());final OptionalEmployee optional employeeList.stream().filter(e - e.getName().equalsIgnoreCase(employee.getName())).findAny();if(optional.isPresent()){employeeList.remove(optional.get());}return employeeList;} } 步骤3在ReactApp组件中定义addEmployee方法/处理程序该方法以员工名称作为POST调用的负载作为我们刚刚在控制器中定义的addEmployee方法的有效负载如下所示 /Users/ArpitAggarwal/react-app/app/components/react-app.jsx addEmployee(employeeName){let _this this;this.Axios.post(/add, {name: employeeName}).then(function (response) {console.log(response);_this.setState({employees: response.data});}).catch(function (error) {console.log(error);}); } 步骤4在ReactApp组件的构造函数中绑定addEmployee处理程序 constructor(props) {super(props);this.state {employees: []};this.addEmployee this.addEmployee.bind(this);this.Axios axios.create({baseURL: /employee,headers: {content-type: application/json, creds:user}}); } 步骤5渲染子组件– AddEmployee作为ReactApp组件渲染方法的一部分将addEmployee处理程序作为react 道具传递以建立父子通信 render() {return (divAddEmployee addEmployee{this.addEmployee}/EmployeeList employees{this.state.employees}//div) } 步骤6在组件目录中创建add-employee组件如下所示 cd react-app/app/components/ touch add-employee.jsx 并复制以下内容 react-app / app / components / add-employee.jsx import React, { Component, PropTypes } from reactexport default class AddEmployee extends React.Component {render(){return (divinput type text ref input /button onClick {(e) this.handleClick(e)}Add Employee/button/div)}handleClick(e) {const node this.refs.inputconst text node.value.trim()console.log(text);this.props.addEmployee(text)node.value } } 如上所定义的handleClicke中函数调用上添加员工按钮点击这将进一步调用使用的道具 ReactApp定义addEmployee处理程序。 完成所有这些操作后我们的react-app可以执行添加员工操作。 接下来我们将进一步扩展该功能以支持删除员工的操作。 步骤7定义deleteEmployee处理程序并以与addEmployee处理程序相同的方式绑定到ReactApp中 /Users/ArpitAggarwal/react-app/app/components/react-app.jsx constructor(props) {super(props);this.state {employees: []};this.addEmployee this.addEmployee.bind(this);this.deleteEmployee this.deleteEmployee.bind(this);this.Axios axios.create({baseURL: /employee,headers: {content-type: application/json, creds:user}}); }deleteEmployee(employeeName){let _this this;this.Axios.post(/delete, {name: employeeName}).then(function (response) {_this.setState({employees: response.data});console.log(response);}).catch(function (error) {console.log(error);}); } 步骤8将 deleteEmployee处理函数传递给EmployeeList组件该组件将进一步将其传递给它的子容器 render() {return (divAddEmployee addEmployee{this.addEmployee}/EmployeeList employees{this.state.employees} deleteEmployee{this.deleteEmployee}//div)} 最终 ReactApp组件应如下所示 use strict; const React require(react); var axios require(axios);import EmployeeList from ./employee-list.jsx import AddEmployee from ./add-employee.jsxexport default class ReactApp extends React.Component {constructor(props) {super(props);this.state {employees: []};this.addEmployee this.addEmployee.bind(this);this.deleteEmployee this.deleteEmployee.bind(this);this.Axios axios.create({baseURL: /employee,headers: {content-type: application/json, creds:user}});}componentDidMount() {let _this this;this.Axios.get(/get).then(function (response) {console.log(response);_this.setState({employees: response.data});}).catch(function (error) {console.log(error);});}addEmployee(employeeName){let _this this;this.Axios.post(/add, {name: employeeName}).then(function (response) {console.log(response);_this.setState({employees: response.data});}).catch(function (error) {console.log(error);});}deleteEmployee(employeeName){let _this this;this.Axios.post(/delete, {name: employeeName}).then(function (response) {_this.setState({employees: response.data});console.log(response);}).catch(function (error) {console.log(error);});}render() {return (divAddEmployee addEmployee{this.addEmployee}/EmployeeList employees{this.state.employees} deleteEmployee{this.deleteEmployee}//div)} } 步骤9更新EmployeeList组件以将deleteEmployee处理程序传递给它的子组件– Employee方法是将其与render方法中的更改一起导入以具有Delete列 const React require(react); import Employee from ./employee.jsxexport default class EmployeeList extends React.Component{render() {var employees this.props.employees.map((employee, i) Employee key{i} employee{employee} deleteEmployee{() this.props.deleteEmployee(employee.name)}/);return (tabletbodytrthID/ththName/ththDepartment/ththDelete/th/tr{employees}/tbody/table)} } 步骤10更新Employee组件以进行渲染– DeleteEmployee组件通过deleteEmployee处理程序 const React require(react); import DeleteEmployee from ./delete-employee.jsxexport default class Employee extends React.Component{render() {return (trtd{this.props.employee.id}/tdtd{this.props.employee.name}/tdtd{this.props.employee.department}/tdtdDeleteEmployee deleteEmployee{this.props.deleteEmployee}//td/tr)} } 步骤11在组件目录内创建delete-employee组件 cd react-app/app/components/ touch delete-employee.jsx 并复制以下内容 react-app / app / components / delete-employee.jsx import React, { Component, PropTypes } from reactexport default class DeleteEmployee extends React.Component {render(){return (button onClick {(employeeName) this.handleDelete(employeeName)}Delete/button)}handleDelete(employeeName) {this.props.deleteEmployee(employeeName);} } 上面定义的handleDeleteemployeeName函数在Delete按钮单击时调用这将进一步使用props调用ReactApp中定义的deleteEmployee处理程序。 一切就绪后目录结构应如下所示 现在重新运行该应用程序并访问http// localhost8080 一旦您添加了几名员工它应如下图所示。 完整的源代码托管在github上 。 翻译自: https://www.javacodegeeks.com/2017/05/handling-events-react.htmlreact 事件处理
http://www.yutouwan.com/news/266858/

相关文章:

  • 丽江古城区建设局网站个人网站可以做音乐下载网
  • 乡镇社区教育中心网站建设林河西网站建设
  • 四川省建行网站wordpress显示最后更新时间
  • 新素材网站基于php mysql的网站开发
  • 餐饮网站建设的模板房产cms系统
  • 网站排行榜网站建设有几大板块
  • 深圳做小程序网站开发dz论坛做分类网站
  • 如何查看网站的浏览量看男科比较正规的医院
  • 十堰市建设工程管理处网站石家庄有哪些公司可以做网站
  • 网站没流量google网站打不开
  • 嘉兴哪里可以做淘宝网站电脑培训班在哪里有最近的
  • 培训网站推荐直聘最新招聘信息
  • 有没有做企业网站的兰州新区规划建设局网站
  • 网站做交叉连接会网站开发没学历
  • 大学生网站开发总结报告移动网站建设制作
  • 有网站域名及空间 别人帮建网站做外贸经常用的网站
  • 湛江做网站需要什么动漫网站设计模板
  • 怎么做网站xml地图网络营销的网站分类有
  • 网站建设.龙兵科技网站如何在google提交收录
  • 网站转换率自学网站建设工资
  • 网站抠图怎么做的html5开发网站
  • ui设计个人作品集seo代码优化步骤
  • 建设银行网站怎么打印明细网站架设
  • 帮人家做网站能赚多少钱网站设计与网站开发是同时进行的
  • 网站代码管理威海营销型网站建设
  • 网站负责人核验照片广州哪家做网站价格好
  • 浙江怎么制作网站网站备案的要求是什么
  • 做室内效果图网站怎样找到工厂直招网站
  • 网站建设代理都有哪些网站建设的费用计入
  • 世界上最有趣的网站广州seo网站优化培训